/* ┌──────────────────────────────────────────────────────────────────────────────┐ │ @author: Davidson Gomes │ │ @file: /app/documentation/components/CodeExamplesSection.tsx │ │ Developed by: Davidson Gomes │ │ Creation date: May 13, 2025 │ │ Contact: contato@evolution-api.com │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @copyright © Evolution API 2025. All rights reserved. │ │ Licensed under the Apache License, Version 2.0 │ │ │ │ You may not use this file except in compliance with the License. │ │ You may obtain a copy of the License at │ │ │ │ http://www.apache.org/licenses/LICENSE-2.0 │ │ │ │ Unless required by applicable law or agreed to in writing, software │ │ distributed under the License is distributed on an "AS IS" BASIS, │ │ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @important │ │ For any future changes to the code in this file, it is recommended to │ │ include, together with the modification, the information of the developer │ │ who changed it and the date of modification. │ └──────────────────────────────────────────────────────────────────────────────┘ */ import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { CodeBlock } from "@/app/documentation/components/CodeBlock"; interface CodeExamplesSectionProps { agentUrl: string; apiKey: string; jsonRpcRequest: any; curlExample: string; fetchExample: string; } export function CodeExamplesSection({ agentUrl, apiKey, jsonRpcRequest, curlExample, fetchExample }: CodeExamplesSectionProps) { const pythonExample = `import requests import json def test_a2a_agent(): url = "${agentUrl || "http://localhost:8000/api/v1/a2a/your-agent-id"}" headers = { "Content-Type": "application/json", "x-api-key": "${apiKey || "your-api-key"}" } payload = ${JSON.stringify(jsonRpcRequest, null, 2)} response = requests.post(url, headers=headers, json=payload) data = response.json() print("Agent response:", data) return data if __name__ == "__main__": test_a2a_agent()`; return ( Code Examples Code snippets ready to use with A2A agents cURL JavaScript Python

Sending files to the agent

You can attach files to messages sent to the agent using the A2A protocol. The files are encoded in base64 and incorporated into the message as parts of type "file".

Python

JavaScript/TypeScript

{ const reader = new FileReader(); reader.onload = () => { const result = reader.result; const base64 = result.split(',')[1]; resolve(base64); }; reader.onerror = reject; reader.readAsDataURL(file); }); } async function sendMessageWithFiles() { // Select file (in a web application) const fileInput = document.getElementById('fileInput'); const files = fileInput.files; if (files.length === 0) { console.error('No file selected'); return; } // Convert file to base64 const file = files[0]; const base64Data = await fileToBase64(file); // Create session and task IDs const sessionId = crypto.randomUUID(); const taskId = crypto.randomUUID(); const callId = crypto.randomUUID(); // Create message with text and file const payload = { jsonrpc: "2.0", method: "message/send", params: { message: { role: "user", parts: [ { type: "text", text: "Analyze this document for me", }, { type: "file", file: { name: file.name, bytes: base64Data, mime_type: file.type } } ], }, sessionId: sessionId, id: taskId, }, id: callId, }; // Send request const response = await fetch('http://localhost:8000/api/v1/a2a/your-agent-id', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': 'your-api-key', }, body: JSON.stringify(payload), }); const data = await response.json(); console.log('Agent response:', data); }`} language="javascript" />

Curl

); }