forked from themanojdesai/python-a2a
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
314 lines (285 loc) · 7.11 KB
/
Copy path__init__.py
File metadata and controls
314 lines (285 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
"""
Python A2A - Agent-to-Agent Protocol
A Python library for implementing Google's Agent-to-Agent (A2A) protocol.
"""
__version__ = "0.5.4"
# Setup feature flags
import sys
import importlib.util
import warnings
# Import basic exceptions first as they're used everywhere
from .exceptions import (
A2AError,
A2AImportError,
A2AConnectionError,
A2AResponseError,
A2ARequestError,
A2AValidationError,
A2AAuthenticationError,
A2AConfigurationError,
A2AStreamingError
)
# All core models - these should be available with basic install
from .models.base import BaseModel
from .models.message import Message, MessageRole
from .models.conversation import Conversation
from .models.content import (
ContentType,
TextContent,
FunctionParameter,
FunctionCallContent,
FunctionResponseContent,
ErrorContent,
Metadata
)
from .models.agent import AgentCard, AgentSkill
from .models.task import Task, TaskStatus, TaskState
# Core client functionality
from .client.base import BaseA2AClient
from .client.http import A2AClient
from .client.network import AgentNetwork
from .client.router import AIAgentRouter
from .client.streaming import StreamingClient
# Core server functionality
from .server.base import BaseA2AServer
from .server.a2a_server import A2AServer
from .server.http import run_server
# Agent discovery functionality
from .discovery import (
AgentRegistry,
run_registry,
DiscoveryClient,
enable_discovery,
RegistryAgent
)
# Utility functions
from .utils.formatting import (
format_message_as_text,
format_conversation_as_text,
pretty_print_message,
pretty_print_conversation
)
from .utils.validation import (
validate_message,
validate_conversation,
is_valid_message,
is_valid_conversation
)
from .utils.conversion import (
create_text_message,
create_function_call,
create_function_response,
create_error_message,
format_function_params,
conversation_to_messages
)
from .utils.decorators import skill, agent
# Workflow components
from .workflow import (
Flow,
WorkflowContext,
WorkflowStep,
QueryStep,
AutoRouteStep,
FunctionStep,
ConditionalBranch,
ConditionStep,
ParallelStep,
ParallelBuilder,
StepType
)
# MCP integration
from .mcp.client import (
MCPClient,
MCPError,
MCPConnectionError,
MCPTimeoutError,
MCPToolError,
MCPTools
)
from .mcp.agent import MCPEnabledAgent
from .mcp.fastmcp import (
FastMCP,
MCPResponse,
text_response,
error_response,
image_response,
multi_content_response,
ContentType as MCPContentType
)
from .mcp.integration import (
FastMCPAgent,
A2AMCPAgent
)
from .mcp.proxy import create_proxy_server
from .mcp.transport import create_fastapi_app
# LangChain integration - Always import the core functions regardless of LangChain availability
from .langchain import (
to_a2a_server,
to_langchain_agent,
to_mcp_server,
to_langchain_tool
)
from .langchain.exceptions import (
LangChainIntegrationError,
LangChainNotInstalledError,
LangChainToolConversionError,
MCPToolConversionError,
LangChainAgentConversionError,
A2AAgentConversionError
)
HAS_LANGCHAIN = importlib.util.find_spec("langchain") is not None or importlib.util.find_spec("langchain_core") is not None
# Optional integration with LLM providers
# These might not be available if the specific provider packages are not installed
try:
from .client.llm import OpenAIA2AClient, AnthropicA2AClient
from .server.llm import OpenAIA2AServer, AnthropicA2AServer, BedrockA2AServer
HAS_LLM_CLIENTS = True
HAS_LLM_SERVERS = True
except ImportError:
HAS_LLM_CLIENTS = False
HAS_LLM_SERVERS = False
# Optional doc generation
try:
from .docs import generate_a2a_docs, generate_html_docs
HAS_DOCS = True
except ImportError:
HAS_DOCS = False
# Optional CLI
try:
from .cli import main as cli_main
HAS_CLI = True
except ImportError:
HAS_CLI = False
# Set feature flags (all core features should be True)
HAS_MODELS = True
HAS_ADVANCED_MODELS = True
HAS_CLIENT_BASE = True
HAS_HTTP_CLIENT = True
HAS_ADVANCED_CLIENTS = True
HAS_SERVER_BASE = True
HAS_SERVER = True
HAS_UTILS = True
HAS_DECORATORS = True
HAS_WORKFLOW = True
HAS_MCP = True
HAS_DISCOVERY = True # Agent discovery
HAS_LANGCHAIN_INTEGRATION = True # Always True since we provide the interface
# Define __all__ for explicit exports
__all__ = [
# Version
'__version__',
# Exceptions
'A2AError',
'A2AImportError',
'A2AConnectionError',
'A2AResponseError',
'A2ARequestError',
'A2AValidationError',
'A2AAuthenticationError',
'A2AConfigurationError',
'A2AStreamingError',
# Models
'BaseModel',
'Message',
'MessageRole',
'Conversation',
'ContentType',
'TextContent',
'FunctionParameter',
'FunctionCallContent',
'FunctionResponseContent',
'ErrorContent',
'Metadata',
'AgentCard',
'AgentSkill',
'Task',
'TaskStatus',
'TaskState',
# Client
'BaseA2AClient',
'A2AClient',
'AgentNetwork',
'AIAgentRouter',
'StreamingClient',
# Server
'BaseA2AServer',
'A2AServer',
'run_server',
# Discovery
'AgentRegistry',
'run_registry',
'DiscoveryClient',
'enable_discovery',
'RegistryAgent',
# Utilities
'format_message_as_text',
'format_conversation_as_text',
'pretty_print_message',
'pretty_print_conversation',
'validate_message',
'validate_conversation',
'is_valid_message',
'is_valid_conversation',
'create_text_message',
'create_function_call',
'create_function_response',
'create_error_message',
'format_function_params',
'conversation_to_messages',
'skill',
'agent',
# Workflow
'Flow',
'WorkflowContext',
'WorkflowStep',
'QueryStep',
'AutoRouteStep',
'FunctionStep',
'ConditionalBranch',
'ConditionStep',
'ParallelStep',
'ParallelBuilder',
'StepType',
# MCP
'MCPClient',
'MCPError',
'MCPConnectionError',
'MCPTimeoutError',
'MCPToolError',
'MCPTools',
'MCPEnabledAgent',
'FastMCP',
'MCPResponse',
'text_response',
'error_response',
'image_response',
'multi_content_response',
'MCPContentType',
'FastMCPAgent',
'A2AMCPAgent',
'create_proxy_server',
'create_fastapi_app',
# LangChain Integration (always included)
'to_a2a_server',
'to_langchain_agent',
'to_mcp_server',
'to_langchain_tool',
'LangChainIntegrationError',
'LangChainNotInstalledError',
'LangChainToolConversionError',
'MCPToolConversionError',
'LangChainAgentConversionError',
'A2AAgentConversionError',
]
# Conditionally add LLM clients/servers
if HAS_LLM_CLIENTS:
__all__.extend(['OpenAIA2AClient', 'AnthropicA2AClient'])
if HAS_LLM_SERVERS:
__all__.extend(['OpenAIA2AServer', 'AnthropicA2AServer', 'BedrockA2AServer'])
# Conditionally add docs
if HAS_DOCS:
__all__.extend(['generate_a2a_docs', 'generate_html_docs'])
# Conditionally add CLI
if HAS_CLI:
__all__.append('cli_main')