Step-by-step guide to integrating Agent-to-Agent (A2A) protocol with Tyler agents
This guide walks you through integrating the Agent-to-Agent (A2A) protocol with your Tyler agents, enabling multi-agent coordination and delegation across different platforms.
import asyncioasync def connect_to_agents(): # Connect to a research specialist agent research_connected = await adapter.connect( name="research_agent", base_url="https://research-ai.example.com" ) # Connect to an analysis specialist agent analysis_connected = await adapter.connect( name="analysis_agent", base_url="https://analysis-ai.example.com" ) if research_connected and analysis_connected: print("✅ Connected to both remote agents") else: print("❌ Failed to connect to one or more agents")asyncio.run(connect_to_agents())
from tyler import Agent# Get delegation tools from connected agentsdelegation_tools = adapter.get_tools_for_agent()# Create Tyler agent that can delegate taskscoordinator = Agent( name="Project Coordinator", model_name="gpt-4o", purpose="""You coordinate complex projects by delegating specialized tasks to remote agents. You have access to: - Research agent: For web research, fact-checking, and information gathering - Analysis agent: For data analysis, insights, and strategic recommendations Use these agents strategically to break down complex requests.""", tools=delegation_tools)
from tyler import Thread, Messageasync def coordinate_project(): # Create a complex request thread = Thread() thread.add_message(Message( role="user", content="""I need a comprehensive market analysis for electric vehicle charging stations. Please: 1. Research current market size, key players, and growth trends 2. Analyze competitive landscape and identify opportunities 3. Provide strategic recommendations for market entry """ )) # The coordinator will automatically delegate to appropriate agents result = await coordinator.go(thread) # Print the coordinated response for message in result.thread.messages: if message.role == "assistant": print(f"Coordinator: {message.content}")asyncio.run(coordinate_project())
from tyler import Agentfrom lye import WEB_TOOLS, FILES_TOOLS# Create a specialized research agentresearch_agent = Agent( name="Research Specialist", model_name="gpt-4o-mini", purpose="""You are an expert research specialist with web search and document processing capabilities. Your expertise includes: - Comprehensive web research and fact-finding - Academic and market research - Document analysis and summarization - Competitive intelligence gathering Always provide well-sourced, accurate information.""", tools=[*WEB_TOOLS, *FILES_TOOLS])
async def start_research_service(): print("🚀 Starting Tyler Research Specialist A2A Server...") print("📡 Other agents can connect at: http://localhost:8000") # Start the server (this will run indefinitely) await server.start_server(host="0.0.0.0", port=8000)# Run the serverif __name__ == "__main__": try: asyncio.run(start_research_service()) except KeyboardInterrupt: print("\n🛑 Server stopped by user")
from tyler.models.execution import EventTypeasync def stream_coordinated_task(): """Example of streaming responses from coordinated agents.""" thread = Thread() thread.add_message(Message( role="user", content="Create a comprehensive business plan for a new AI startup" )) print("🎯 Starting coordinated task execution...") print("=" * 50) async for update in coordinator.go(thread, stream=True): if update.type == EventType.LLM_STREAM_CHUNK: print(update.data.get("content_chunk", ""), end="", flush=True) elif update.type == EventType.TOOL_SELECTED: tool_name = update.data.get("tool_name", "") if "delegate_to_" in tool_name: agent_name = tool_name.replace("delegate_to_", "") print(f"\n\n🤝 Delegating to {agent_name}...") print() elif update.type == EventType.EXECUTION_COMPLETE: print("\n\n✅ Task coordination complete!")