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
216 lines (186 loc) · 4.42 KB
/
Copy path__init__.py
File metadata and controls
216 lines (186 loc) · 4.42 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
"""
Python A2A - Agent-to-Agent Protocol
A Python library for implementing Google's Agent-to-Agent (A2A) protocol.
"""
__version__ = "0.2.0"
# Import core models
from .models import (
Message,
MessageRole,
Conversation,
TextContent,
FunctionParameter,
FunctionCallContent,
FunctionResponseContent,
ErrorContent,
Metadata,
ContentType
)
# Import clients
from .client import (
BaseA2AClient,
A2AClient,
OpenAIA2AClient,
AnthropicA2AClient
)
# Import servers
from .server import (
BaseA2AServer,
A2AServer,
run_server,
OpenAIA2AServer,
AnthropicA2AServer
)
# Import utility functions
from .utils import (
# Formatting utilities
format_message_as_text,
format_conversation_as_text,
pretty_print_message,
pretty_print_conversation,
# Validation utilities
validate_message,
validate_conversation,
is_valid_message,
is_valid_conversation,
# Conversion utilities
create_text_message,
create_function_call,
create_function_response,
create_error_message,
format_function_params,
conversation_to_messages
)
# Import exceptions
from .exceptions import (
A2AError,
A2AImportError,
A2AConnectionError,
A2AResponseError,
A2ARequestError,
A2AValidationError,
A2AAuthenticationError,
A2AConfigurationError
)
# Expose command-line interface
from .cli import main as cli_main
# Import MCP integration with improved error handling
try:
# MCP client
from .mcp.client import (
MCPClient,
MCPError,
MCPConnectionError,
MCPTimeoutError,
MCPToolError,
MCPTools
)
# MCP agent integration
from .mcp.agent import MCPEnabledAgent
# FastMCP implementation
from .mcp.fastmcp import (
FastMCP,
MCPResponse,
text_response,
error_response,
image_response,
multi_content_response,
ContentType as MCPContentType
)
# Improved agent integration
from .mcp.integration import (
FastMCPAgent,
A2AMCPAgent
)
# Proxy functionality
from .mcp.proxy import create_proxy_server
# Transport for easy imports
from .mcp.transport import create_fastapi_app
HAS_MCP = True
except ImportError as e:
# Print more detailed error information to help diagnose import issues
import sys
print(f"Warning: MCP module could not be imported: {e}", file=sys.stderr)
HAS_MCP = False
# Base package exports
__all__ = [
# Version
'__version__',
# Models
'Message',
'MessageRole',
'Conversation',
'TextContent',
'FunctionParameter',
'FunctionCallContent',
'FunctionResponseContent',
'ErrorContent',
'Metadata',
'ContentType',
# Clients
'BaseA2AClient',
'A2AClient',
'OpenAIA2AClient',
'AnthropicA2AClient',
# Servers
'BaseA2AServer',
'A2AServer',
'run_server',
'OpenAIA2AServer',
'AnthropicA2AServer',
# 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',
# Exceptions
'A2AError',
'A2AImportError',
'A2AConnectionError',
'A2AResponseError',
'A2ARequestError',
'A2AValidationError',
'A2AAuthenticationError',
'A2AConfigurationError',
# CLI
'cli_main',
]
# Add MCP classes if available
if HAS_MCP:
# Add to __all__ list
__all__.extend([
# MCP client
'MCPClient',
'MCPError',
'MCPConnectionError',
'MCPTimeoutError',
'MCPToolError',
'MCPTools',
# MCP agent integration
'MCPEnabledAgent',
# FastMCP implementation
'FastMCP',
'MCPResponse',
'text_response',
'error_response',
'image_response',
'multi_content_response',
'MCPContentType',
# Improved agent integration
'FastMCPAgent',
'A2AMCPAgent',
# Proxy functionality
'create_proxy_server',
# Transport
'create_fastapi_app'
])