@@ -62,64 +62,64 @@ flowchart LR
62623 . 配置服务器参数(端口、主机等)
6363=== "代码"
6464
65- ```python title="server.py" linenums="1" hl_lines="5 "
66- from google.adk.a2a.utils.agent_to_a2a import to_a2a
67- from veadk import Agent
68- from veadk.tools.demo_tools import get_city_weather
69-
70- agent = Agent(
71- name="weather_agent",
72- description="An agent that can get the weather of a city",
73- tools=[get_city_weather],
74- )
75-
76- app = to_a2a(agent=agent)
77- ```
65+ ``` python title="server.py" linenums="1" hl_lines="1 11 "
66+ from google.adk.a2a.utils.agent_to_a2a import to_a2a
67+ from veadk import Agent
68+ from veadk.tools.demo_tools import get_city_weather
69+
70+ agent = Agent(
71+ name = " weather_agent" ,
72+ description = " An agent that can get the weather of a city" ,
73+ tools = [get_city_weather],
74+ )
75+
76+ app = to_a2a(agent = agent)
77+ ```
7878### 客户端集成
79791 . 导入 RemoteVeAgent 类
80802 . 配置远程 Agent 连接参数
81813 . 在 Root Agent 中添加 Remote Agent 作为 Sub Agent
8282=== "代码"
8383
84- ```python title="client.py" linenums="1"
85- from veadk import Agent, Runner
86- from veadk.a2a.remote_ve_agent import RemoteVeAgent
87-
88- async def main(prompt: str) -> str:
89- """Main function for run an agent.
84+ ``` python title="client.py" linenums="1"
85+ from veadk import Agent, Runner
86+ from veadk.a2a.remote_ve_agent import RemoteVeAgent
9087
91- Args :
92- prompt (str): The prompt to run .
88+ async def main ( prompt : str ) -> str :
89+ """ Main function for run an agent .
9390
94- Returns:
95- str: The response from the agent.
96- """
97- weather_agent = RemoteVeAgent(
98- name="weather_agent",
99- url="http://localhost:8000/", # <--- url of A2A server
100- )
101- print(f"Remote agent name is {weather_agent.name}.")
102- print(f"Remote agent description is {weather_agent.description}.")
91+ Args:
92+ prompt (str): The prompt to run.
10393
104- agent = Agent(
105- name="root_agent",
106- description="An assistant for fetching weather.",
107- instruction="You are a helpful assistant. You can invoke weather agent to get weather information.",
108- sub_agents=[weather_agent],
109- )
94+ Returns:
95+ str: The response from the agent.
96+ """
97+ weather_agent = RemoteVeAgent(
98+ name = " weather_agent" ,
99+ url = " http://localhost:8000/" , # <--- url of A2A server
100+ )
101+ print (f " Remote agent name is { weather_agent.name} . " )
102+ print (f " Remote agent description is { weather_agent.description} . " )
103+
104+ agent = Agent(
105+ name = " root_agent" ,
106+ description = " An assistant for fetching weather." ,
107+ instruction = " You are a helpful assistant. You can invoke weather agent to get weather information." ,
108+ sub_agents = [weather_agent],
109+ )
110110
111- runner = Runner(agent=agent)
112- response = await runner.run(messages=prompt)
111+ runner = Runner(agent = agent)
112+ response = await runner.run(messages = prompt)
113113
114- return response
114+ return response
115115
116116
117- if __name__ == "__main__":
118- import asyncio
117+ if __name__ == " __main__" :
118+ import asyncio
119119
120- response = asyncio.run(main("What is the weather like of Beijing?"))
121- print(response)
122- ```
120+ response = asyncio.run(main(" What is the weather like of Beijing?" ))
121+ print (response)
122+ ```
123123### 交互流程
124124下图为示例对应的交互流程图
125125``` mermaid
@@ -195,52 +195,52 @@ veADK 的 A2A 鉴权机制提供了灵活的认证选项,支持标准的 Beare
195195
196196=== "代码"
197197 ```python title="client.py" linenums="1"
198- # <...code truncated...>
198+ # <...code truncated...>
199+
200+ # 创建自定义的 httpx.AsyncClient 实例
201+ custom_client = httpx.AsyncClient(
202+ # 基础 URL 设置
203+ base_url="https://vefaas.example.com/agents/ ",
204+
205+ # 超时设置(秒)
206+ timeout=30.0,
207+
208+ # 连接池设置
209+ limits=httpx.Limits(
210+ max_connections=100, # 最大并发连接数
211+ max_keepalive_connections=20, # 最大保活连接数
212+ keepalive_expiry=60.0, # 保活连接过期时间
213+ ),
214+
215+ # 重试配置(需要 httpx >= 0.24.0)
216+ follow_redirects=True, # 跟随重定向
199217
200- # 创建自定义的 httpx.AsyncClient 实例
201- custom_client = httpx.AsyncClient(
202- # 基础 URL 设置
203- base_url="https://vefaas.example.com/agents/ ",
204-
205- # 超时设置(秒)
206- timeout=30.0,
207-
208- # 连接池设置
209- limits=httpx.Limits(
210- max_connections=100, # 最大并发连接数
211- max_keepalive_connections=20, # 最大保活连接数
212- keepalive_expiry=60.0, # 保活连接过期时间
213- ),
214-
215- # 重试配置(需要 httpx >= 0.24.0)
216- follow_redirects=True, # 跟随重定向
217-
218- # 自定义默认请求头
219- headers={
220- "User-Agent": "Custom-VeADK-Client/1.0",
221- "X-Custom-Header": "custom-value"
222- },
223-
224- # SSL 验证选项(生产环境中建议保持默认的 True)
225- verify=True,
226-
227- # 代理配置(如需使用代理)
228- proxies="http://proxy.example.com:8080 ",
229-
230- # 并发请求设置
231- http2=True, # 启用 HTTP/2 支持
232- )
218+ # 自定义默认请求头
219+ headers={
220+ "User-Agent": "Custom-VeADK-Client/1.0",
221+ "X-Custom-Header": "custom-value"
222+ },
233223
234- # 创建 RemoteVeAgent 实例时,将自定义客户端传递给 httpx_client 参数
235- remote_agent = RemoteVeAgent(
236- name="a2a_agent",
237- url="https://example.com/a2a ",
238- auth_token="your_token_here",
239- auth_method="header",
240- httpx_client=custom_client,
241- )
242-
243- # <...code truncated...>
224+ # SSL 验证选项(生产环境中建议保持默认的 True)
225+ verify=True,
226+
227+ # 代理配置(如需使用代理)
228+ proxies="http://proxy.example.com:8080 ",
229+
230+ # 并发请求设置
231+ http2=True, # 启用 HTTP/2 支持
232+ )
233+
234+ # 创建 RemoteVeAgent 实例时,将自定义客户端传递给 httpx_client 参数
235+ remote_agent = RemoteVeAgent(
236+ name="a2a_agent",
237+ url="https://example.com/a2a ",
238+ auth_token="your_token_here",
239+ auth_method="header",
240+ httpx_client=custom_client,
241+ )
242+
243+ # <...code truncated...>
244244 ```
245245
246246
0 commit comments