traia-iatp 0.1.29__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of traia-iatp might be problematic. Click here for more details.

Files changed (107) hide show
  1. traia_iatp/README.md +368 -0
  2. traia_iatp/__init__.py +54 -0
  3. traia_iatp/cli/__init__.py +5 -0
  4. traia_iatp/cli/main.py +483 -0
  5. traia_iatp/client/__init__.py +10 -0
  6. traia_iatp/client/a2a_client.py +274 -0
  7. traia_iatp/client/crewai_a2a_tools.py +335 -0
  8. traia_iatp/client/d402_a2a_client.py +293 -0
  9. traia_iatp/client/grpc_a2a_tools.py +349 -0
  10. traia_iatp/client/root_path_a2a_client.py +1 -0
  11. traia_iatp/contracts/__init__.py +12 -0
  12. traia_iatp/contracts/iatp_contracts_config.py +263 -0
  13. traia_iatp/contracts/wallet_creator.py +255 -0
  14. traia_iatp/core/__init__.py +43 -0
  15. traia_iatp/core/models.py +172 -0
  16. traia_iatp/d402/__init__.py +55 -0
  17. traia_iatp/d402/chains.py +102 -0
  18. traia_iatp/d402/client.py +150 -0
  19. traia_iatp/d402/clients/__init__.py +7 -0
  20. traia_iatp/d402/clients/base.py +218 -0
  21. traia_iatp/d402/clients/httpx.py +219 -0
  22. traia_iatp/d402/common.py +114 -0
  23. traia_iatp/d402/encoding.py +28 -0
  24. traia_iatp/d402/examples/client_example.py +197 -0
  25. traia_iatp/d402/examples/server_example.py +171 -0
  26. traia_iatp/d402/facilitator.py +453 -0
  27. traia_iatp/d402/fastapi_middleware/__init__.py +6 -0
  28. traia_iatp/d402/fastapi_middleware/middleware.py +225 -0
  29. traia_iatp/d402/fastmcp_middleware.py +147 -0
  30. traia_iatp/d402/mcp_middleware.py +434 -0
  31. traia_iatp/d402/middleware.py +193 -0
  32. traia_iatp/d402/models.py +116 -0
  33. traia_iatp/d402/networks.py +98 -0
  34. traia_iatp/d402/path.py +43 -0
  35. traia_iatp/d402/payment_introspection.py +104 -0
  36. traia_iatp/d402/payment_signing.py +178 -0
  37. traia_iatp/d402/paywall.py +119 -0
  38. traia_iatp/d402/starlette_middleware.py +326 -0
  39. traia_iatp/d402/template.py +1 -0
  40. traia_iatp/d402/types.py +300 -0
  41. traia_iatp/mcp/__init__.py +18 -0
  42. traia_iatp/mcp/client.py +201 -0
  43. traia_iatp/mcp/d402_mcp_tool_adapter.py +361 -0
  44. traia_iatp/mcp/mcp_agent_template.py +481 -0
  45. traia_iatp/mcp/templates/Dockerfile.j2 +80 -0
  46. traia_iatp/mcp/templates/README.md.j2 +310 -0
  47. traia_iatp/mcp/templates/cursor-rules.md.j2 +520 -0
  48. traia_iatp/mcp/templates/deployment_params.json.j2 +20 -0
  49. traia_iatp/mcp/templates/docker-compose.yml.j2 +32 -0
  50. traia_iatp/mcp/templates/dockerignore.j2 +47 -0
  51. traia_iatp/mcp/templates/env.example.j2 +57 -0
  52. traia_iatp/mcp/templates/gitignore.j2 +77 -0
  53. traia_iatp/mcp/templates/mcp_health_check.py.j2 +150 -0
  54. traia_iatp/mcp/templates/pyproject.toml.j2 +32 -0
  55. traia_iatp/mcp/templates/pyrightconfig.json.j2 +22 -0
  56. traia_iatp/mcp/templates/run_local_docker.sh.j2 +390 -0
  57. traia_iatp/mcp/templates/server.py.j2 +175 -0
  58. traia_iatp/mcp/traia_mcp_adapter.py +543 -0
  59. traia_iatp/preview_diagrams.html +181 -0
  60. traia_iatp/registry/__init__.py +26 -0
  61. traia_iatp/registry/atlas_search_indexes.json +280 -0
  62. traia_iatp/registry/embeddings.py +298 -0
  63. traia_iatp/registry/iatp_search_api.py +846 -0
  64. traia_iatp/registry/mongodb_registry.py +771 -0
  65. traia_iatp/registry/readmes/ATLAS_SEARCH_INDEXES.md +252 -0
  66. traia_iatp/registry/readmes/ATLAS_SEARCH_SETUP.md +134 -0
  67. traia_iatp/registry/readmes/AUTHENTICATION_UPDATE.md +124 -0
  68. traia_iatp/registry/readmes/EMBEDDINGS_SETUP.md +172 -0
  69. traia_iatp/registry/readmes/IATP_SEARCH_API_GUIDE.md +257 -0
  70. traia_iatp/registry/readmes/MONGODB_X509_AUTH.md +208 -0
  71. traia_iatp/registry/readmes/README.md +251 -0
  72. traia_iatp/registry/readmes/REFACTORING_SUMMARY.md +191 -0
  73. traia_iatp/scripts/__init__.py +2 -0
  74. traia_iatp/scripts/create_wallet.py +244 -0
  75. traia_iatp/server/__init__.py +15 -0
  76. traia_iatp/server/a2a_server.py +219 -0
  77. traia_iatp/server/example_template_usage.py +72 -0
  78. traia_iatp/server/iatp_server_agent_generator.py +237 -0
  79. traia_iatp/server/iatp_server_template_generator.py +235 -0
  80. traia_iatp/server/templates/.dockerignore.j2 +48 -0
  81. traia_iatp/server/templates/Dockerfile.j2 +49 -0
  82. traia_iatp/server/templates/README.md +137 -0
  83. traia_iatp/server/templates/README.md.j2 +425 -0
  84. traia_iatp/server/templates/__init__.py +1 -0
  85. traia_iatp/server/templates/__main__.py.j2 +565 -0
  86. traia_iatp/server/templates/agent.py.j2 +94 -0
  87. traia_iatp/server/templates/agent_config.json.j2 +22 -0
  88. traia_iatp/server/templates/agent_executor.py.j2 +279 -0
  89. traia_iatp/server/templates/docker-compose.yml.j2 +23 -0
  90. traia_iatp/server/templates/env.example.j2 +84 -0
  91. traia_iatp/server/templates/gitignore.j2 +78 -0
  92. traia_iatp/server/templates/grpc_server.py.j2 +218 -0
  93. traia_iatp/server/templates/pyproject.toml.j2 +78 -0
  94. traia_iatp/server/templates/run_local_docker.sh.j2 +103 -0
  95. traia_iatp/server/templates/server.py.j2 +243 -0
  96. traia_iatp/special_agencies/__init__.py +4 -0
  97. traia_iatp/special_agencies/registry_search_agency.py +392 -0
  98. traia_iatp/utils/__init__.py +10 -0
  99. traia_iatp/utils/docker_utils.py +251 -0
  100. traia_iatp/utils/general.py +64 -0
  101. traia_iatp/utils/iatp_utils.py +126 -0
  102. traia_iatp-0.1.29.dist-info/METADATA +423 -0
  103. traia_iatp-0.1.29.dist-info/RECORD +107 -0
  104. traia_iatp-0.1.29.dist-info/WHEEL +5 -0
  105. traia_iatp-0.1.29.dist-info/entry_points.txt +2 -0
  106. traia_iatp-0.1.29.dist-info/licenses/LICENSE +21 -0
  107. traia_iatp-0.1.29.dist-info/top_level.txt +1 -0
traia_iatp/README.md ADDED
@@ -0,0 +1,368 @@
1
+ # Inter-Agent Transfer Protocol (IATP)
2
+
3
+ The IATP folder implements the Inter-Agent Transfer Protocol, enabling AI Agents to utilize other AI Agents as tools. This implementation uses the A2A protocol library as the underlying communication mechanism and allows CrewAI agents to act as both IATP servers (utility agents) and clients.
4
+
5
+ ## Overview
6
+
7
+ The IATP implementation provides:
8
+ - **Utility Agent Creation**: Convert MCP servers into IATP-compatible utility agents
9
+ - **IATP Client Tools**: Enable CrewAI crews to use utility agents as tools via IATP protocol
10
+ - **Protocol Support**: HTTP/2 with SSE streaming and optional gRPC for high-performance scenarios
11
+ - **Registry Management**: MongoDB-based registry for discovering utility agents
12
+
13
+ ## Architecture
14
+
15
+ ### A. Utility Agent (IATP Server) Flow
16
+
17
+ ```mermaid
18
+ graph LR
19
+ A[MCP Server] --> B[Utility Agent Generator]
20
+ B --> C[IATP Server with HTTP/2 + SSE]
21
+ B --> D[Optional gRPC Server]
22
+ C --> E[Docker Container]
23
+ E --> F[MongoDB Registry]
24
+
25
+ style A fill:#f9f,stroke:#333,stroke-width:2px
26
+ style C fill:#9f9,stroke:#333,stroke-width:2px
27
+ style D fill:#9ff,stroke:#333,stroke-width:2px
28
+ ```
29
+
30
+ ### B. CrewAI Client (IATP Client) Flow
31
+
32
+ ```mermaid
33
+ graph LR
34
+ A[CrewAI Agent] --> B[IATP Tool]
35
+ B --> C{Protocol}
36
+ C -->|HTTP/2| D[IATP HTTP Client]
37
+ C -->|gRPC| E[IATP gRPC Client]
38
+ D --> F[Utility Agent]
39
+ E --> F
40
+ F --> G[MCP Server]
41
+
42
+ style A fill:#f9f,stroke:#333,stroke-width:2px
43
+ style B fill:#9f9,stroke:#333,stroke-width:2px
44
+ style F fill:#ff9,stroke:#333,stroke-width:2px
45
+ ```
46
+
47
+ ## IATP Operation Modes
48
+
49
+ The IATP protocol supports two distinct operation modes, each designed for different use cases:
50
+
51
+ ### 1. Synchronous JSON-RPC Mode
52
+
53
+ This is the default mode for simple request-response patterns:
54
+
55
+ **How it works:**
56
+ - Client sends: `message/send` request via JSON-RPC
57
+ - Server processes the request using CrewAI agents
58
+ - Server returns: A single `Message` result
59
+ - The `ResultAggregator` waits for exactly ONE message to complete the request
60
+
61
+ **When to use:**
62
+ - Direct questions requiring one answer
63
+ - Traditional API-like interactions
64
+ - When you need a complete response before proceeding
65
+ - CrewAI operations that produce a final result
66
+
67
+ **Example flow:**
68
+ ```
69
+ Client: "What is the current BTC price?"
70
+ Server: Processes request...
71
+ Server: Returns: "The current BTC price is $107,398.50"
72
+ ```
73
+
74
+ **Important:** In this mode, the agent executor should only send ONE message to the event queue. Sending multiple events (like status updates) will confuse the `ResultAggregator` and cause timeouts.
75
+
76
+ ### 2. Asynchronous Streaming Mode (SSE)
77
+
78
+ This mode uses Server-Sent Events for real-time updates and long-running operations:
79
+
80
+ **How it works:**
81
+ - Client sends: `message/send` with `output_mode: "text/event-stream"`
82
+ - Server returns: A `Task` object with an ID immediately
83
+ - Client subscribes: Connects to `/a2a/tasks/subscribe` endpoint for SSE
84
+ - Server streams: Multiple events using `CustomEvent` objects
85
+
86
+ **When to use:**
87
+ - Long-running operations with progress updates
88
+ - Real-time data feeds (market prices, trading signals)
89
+ - Multi-step workflows where intermediate results matter
90
+ - When you need to show progress to users
91
+
92
+ **Event types in streaming mode:**
93
+ - `stream_start`: Indicates streaming has begun
94
+ - `stream_chunk`: Contains a chunk of data
95
+ - `message`: Standard message updates
96
+ - `progress`: Progress updates with percentage
97
+ - `status`: Task status changes (RUNNING, COMPLETED, FAILED)
98
+ - `stream_complete`: Indicates streaming has finished
99
+ - `stream_error`: Error occurred during streaming
100
+
101
+ **Example flow:**
102
+ ```
103
+ Client: "Monitor BTC price for the next minute"
104
+ Server: Returns Task ID: "task_123"
105
+ Client: Subscribes to SSE endpoint
106
+ Server: Sends stream_start event
107
+ Server: Sends stream_chunk: "BTC: $107,398.50"
108
+ Server: Sends stream_chunk: "BTC: $107,401.25"
109
+ Server: Sends stream_chunk: "BTC: $107,395.00"
110
+ Server: Sends stream_complete event
111
+ ```
112
+
113
+ ### Implementation Guidelines
114
+
115
+ **For Synchronous Mode:**
116
+ ```python
117
+ # In agent_executor.py
118
+ async def _execute_standard(self, context, event_queue, request_text):
119
+ # Process request
120
+ result = process_with_crewai(request_text)
121
+
122
+ # Send ONLY ONE message
123
+ msg = new_agent_text_message(str(result))
124
+ msg.taskId = context.task_id # Important: Set task ID
125
+ await event_queue.enqueue_event(msg)
126
+ ```
127
+
128
+ **For Streaming Mode:**
129
+ ```python
130
+ # In agent_executor.py
131
+ async def _execute_streaming(self, context, event_queue, request_text):
132
+ # Send start event
133
+ await event_queue.enqueue_event(
134
+ CustomEvent("stream_start", {"message": "Starting"})
135
+ )
136
+
137
+ # Stream chunks
138
+ async for chunk in get_streaming_data():
139
+ await event_queue.enqueue_event(
140
+ CustomEvent("stream_chunk", {"content": chunk})
141
+ )
142
+
143
+ # Send completion
144
+ await event_queue.enqueue_event(
145
+ CustomEvent("stream_complete", {"message": "Done"})
146
+ )
147
+ ```
148
+
149
+ ## Key Components
150
+
151
+ ### 1. Server Components (`iatp/server/`)
152
+
153
+ - **`templates/`**: Jinja2 templates for generating utility agents
154
+ - `__main__.py.j2`: Main entry point with HTTP/2 and SSE support
155
+ - `agent_executor.py.j2`: Executor with streaming capabilities
156
+ - `grpc_server.py.j2`: Optional gRPC server implementation
157
+ - `pyproject.toml.j2`: Dependencies including HTTP/2 and optional gRPC
158
+
159
+ ### 2. Client Components (`iatp/client/`)
160
+
161
+ - **`crewai_a2a_tools.py`**: HTTP/2-based IATP tools for CrewAI (using A2A protocol)
162
+ - Persistent HTTP/2 connections with multiplexing
163
+ - SSE streaming support for real-time data
164
+ - Connection pooling and retry logic
165
+
166
+ - **`grpc_a2a_tools.py`**: gRPC-based IATP tools for high-performance scenarios
167
+ - Channel pooling for load distribution
168
+ - Unary, server-streaming, and bidirectional streaming
169
+ - Built-in retry and circuit breaker patterns
170
+
171
+ ### 3. Registry Components (`iatp/registry/`)
172
+
173
+ - **`iatp_registry_api.py`**: High-level API for registry operations
174
+ - Find and list MCP servers
175
+ - No direct MongoDB exposure to utility agents
176
+
177
+ ## Protocol Features
178
+
179
+ ### HTTP/2 with SSE Streaming
180
+
181
+ **When to use**: Default choice for most scenarios
182
+ - ✅ Wide compatibility
183
+ - ✅ Works through proxies and load balancers
184
+ - ✅ Human-readable protocol
185
+ - ✅ Built-in browser support for debugging
186
+
187
+ **Features**:
188
+ - HTTP/2 multiplexing: Multiple concurrent requests over single connection
189
+ - Server-Sent Events: Real-time streaming responses
190
+ - Keep-alive connections: Reduced latency
191
+ - Automatic reconnection: Built into SSE protocol
192
+
193
+ ### gRPC Support
194
+
195
+ **When to use**: High-performance, low-latency scenarios
196
+ - ✅ Binary protocol: More efficient than HTTP/JSON
197
+ - ✅ Strongly typed: Protocol buffer definitions
198
+ - ✅ Bidirectional streaming: Full-duplex communication
199
+ - ✅ Built-in flow control and backpressure
200
+
201
+ **Features**:
202
+ - Channel pooling: Load distribution across connections
203
+ - All streaming modes: Unary, server-streaming, client-streaming, bidirectional
204
+ - Reflection support: Runtime service discovery
205
+ - Configurable message sizes and stream limits
206
+
207
+ ## Usage Examples
208
+
209
+ ### Creating a Utility Agent
210
+
211
+ ```python
212
+ from traia_iatp.server import IATPServerAgentGenerator
213
+ from traia_iatp.core.models import MCPServer, MCPServerType
214
+
215
+ # Create MCP server specification
216
+ mcp_server = MCPServer(
217
+ id="hyperliquid-mcp-001",
218
+ name="hyperliquid-mcp",
219
+ url="http://localhost:3000/mcp",
220
+ server_type=MCPServerType.STREAMABLE_HTTP,
221
+ description="Trading tools for Hyperliquid DEX",
222
+ capabilities=["get_market_data", "place_order", "get_positions"]
223
+ )
224
+
225
+ # Generate utility agent
226
+ generator = IATPServerAgentGenerator()
227
+ agent = generator.generate_agent(
228
+ mcp_server=mcp_server,
229
+ agent_name="Hyperliquid Trading Agent",
230
+ agent_description="Trading on Hyperliquid DEX"
231
+ )
232
+ ```
233
+
234
+ ### Using HTTP/2 A2A Tools in CrewAI
235
+
236
+ ```python
237
+ from traia_iatp.client.crewai_a2a_tools import A2AToolkit
238
+
239
+ # Create HTTP/2 tool with streaming support
240
+ tool = A2AToolkit.create_tool_from_endpoint(
241
+ endpoint="http://localhost:8000",
242
+ name="Trading Agent",
243
+ description="Execute trades via A2A"
244
+ )
245
+
246
+ # Use in CrewAI agent
247
+ agent = Agent(
248
+ role="Trader",
249
+ tools=[tool]
250
+ )
251
+
252
+ # Basic usage
253
+ result = await tool._arun("Get current BTC price")
254
+ print(f"Price: {result}")
255
+ ```
256
+
257
+ ### Using gRPC A2A Tools
258
+
259
+ ```python
260
+ from traia_iatp.client.grpc_a2a_tools import GrpcA2AToolkit
261
+
262
+ # Create gRPC tool for high-performance
263
+ tool = GrpcA2AToolkit.create_tool_from_endpoint(
264
+ endpoint="localhost:50051",
265
+ name="Trading Agent gRPC",
266
+ description="High-frequency trading via gRPC",
267
+ pool_size=20, # More channels for high load
268
+ use_tls=True
269
+ )
270
+
271
+ # Use same interface as HTTP tools
272
+ result = await tool._arun("Execute trade: BUY 0.1 BTC")
273
+ ```
274
+
275
+ ## Streaming Patterns
276
+
277
+ ### SSE Streaming (HTTP/2)
278
+
279
+ ```mermaid
280
+ sequenceDiagram
281
+ participant Client
282
+ participant A2A Server
283
+ participant MCP Server
284
+
285
+ Client->>A2A Server: POST /a2a/tasks/subscribe
286
+ A2A Server->>Client: 200 OK (SSE stream)
287
+ A2A Server->>Client: event: connection
288
+
289
+ loop Streaming
290
+ A2A Server->>MCP Server: Process chunk
291
+ MCP Server->>A2A Server: Result chunk
292
+ A2A Server->>Client: event: stream_chunk
293
+ end
294
+
295
+ A2A Server->>Client: event: stream_complete
296
+ A2A Server->>Client: event: [DONE]
297
+ ```
298
+
299
+ ### gRPC Streaming
300
+
301
+ ```mermaid
302
+ sequenceDiagram
303
+ participant Client
304
+ participant gRPC Server
305
+ participant MCP Server
306
+
307
+ Client->>gRPC Server: StreamMessage RPC
308
+
309
+ loop Streaming
310
+ gRPC Server->>MCP Server: Process
311
+ MCP Server->>gRPC Server: Result
312
+ gRPC Server->>Client: StreamResponse
313
+ end
314
+
315
+ gRPC Server->>Client: Stream End
316
+ ```
317
+
318
+ ## Performance Considerations
319
+
320
+ ### HTTP/2 vs gRPC
321
+
322
+ | Feature | HTTP/2 + SSE | gRPC |
323
+ |---------|--------------|------|
324
+ | Protocol | Text (JSON) | Binary (Protobuf) |
325
+ | Streaming | Server-only | Bidirectional |
326
+ | Browser Support | Yes | Limited |
327
+ | Debugging | Easy | Requires tools |
328
+ | Performance | Good | Excellent |
329
+ | Message Size | Flexible | Fixed by proto |
330
+
331
+ ### Connection Pooling
332
+
333
+ Both protocols support connection pooling:
334
+ - **HTTP/2**: Single connection with up to 100 concurrent streams
335
+ - **gRPC**: Multiple channels with round-robin distribution
336
+
337
+ ## Deployment
338
+
339
+ ### Docker Support
340
+
341
+ Generated utility agents include:
342
+ - Multi-protocol support in single container
343
+ - Health checks for both HTTP and gRPC endpoints
344
+ - Environment-based configuration
345
+
346
+ ### Environment Variables
347
+
348
+ ```bash
349
+ # HTTP/2 Server
350
+ PORT=8000
351
+ HOST=0.0.0.0
352
+
353
+ # gRPC Server (optional)
354
+ GRPC_PORT=50051
355
+
356
+ # TLS Support
357
+ USE_TLS=true
358
+ TLS_CERT_PATH=/certs/server.crt
359
+ TLS_KEY_PATH=/certs/server.key
360
+ ```
361
+
362
+ ## Future Enhancements
363
+
364
+ 1. **WebSocket Support**: For browser-based clients
365
+ 2. **GraphQL Gateway**: Unified query interface
366
+ 3. **Service Mesh Integration**: Istio/Linkerd support
367
+ 4. **Distributed Tracing**: OpenTelemetry integration
368
+ 5. **Protocol Buffer Registry**: Centralized schema management
traia_iatp/__init__.py ADDED
@@ -0,0 +1,54 @@
1
+ """Traia IATP - Inter Agent Transfer Protocol package."""
2
+
3
+ from .core.models import UtilityAgent, MCPServer, AgentCard
4
+ from .server.iatp_server_agent_generator import IATPServerAgentGenerator
5
+ from .registry.mongodb_registry import UtilityAgentRegistry, MCPServerRegistry
6
+ from .registry.iatp_search_api import find_utility_agent
7
+ from .client.a2a_client import UtilityAgencyTool, create_utility_agency_tools
8
+ from .utils.docker_utils import LocalDockerRunner, run_generated_agent_locally, use_run_local_docker_script
9
+
10
+ # D402 payment integration
11
+ from .d402 import (
12
+ D402Config,
13
+ D402PaymentInfo,
14
+ D402ServicePrice,
15
+ PaymentScheme,
16
+ D402IATPMiddleware,
17
+ require_iatp_payment,
18
+ D402IATPClient,
19
+ IATPSettlementFacilitator,
20
+ )
21
+ from .client.d402_a2a_client import D402A2AClient, create_d402_a2a_client
22
+
23
+ __version__ = "0.1.23"
24
+
25
+ __all__ = [
26
+ # Core models
27
+ "UtilityAgent",
28
+ "MCPServer",
29
+ "AgentCard",
30
+ # Server components
31
+ "IATPServerAgentGenerator",
32
+ # Registry
33
+ "UtilityAgentRegistry",
34
+ "MCPServerRegistry",
35
+ "find_utility_agent",
36
+ # Client
37
+ "UtilityAgencyTool",
38
+ "create_utility_agency_tools",
39
+ # Docker utilities
40
+ "LocalDockerRunner",
41
+ "run_generated_agent_locally",
42
+ "use_run_local_docker_script",
43
+ # D402 payment integration
44
+ "D402Config",
45
+ "D402PaymentInfo",
46
+ "D402ServicePrice",
47
+ "PaymentScheme",
48
+ "D402IATPMiddleware",
49
+ "require_iatp_payment",
50
+ "D402IATPClient",
51
+ "IATPSettlementFacilitator",
52
+ "D402A2AClient",
53
+ "create_d402_a2a_client",
54
+ ]
@@ -0,0 +1,5 @@
1
+ """IATP CLI module."""
2
+
3
+ from .main import app
4
+
5
+ __all__ = ["app"]