diff --git a/5_a2a_integration/README.md b/5_a2a_integration/README.md index bfc6dcc..1173e6f 100644 --- a/5_a2a_integration/README.md +++ b/5_a2a_integration/README.md @@ -182,8 +182,8 @@ In `agents/gamemaster_orchestrator/gamemaster_orchestrator.py`, establish mystic ```python # TODO: Initialize A2AClientToolProvider with known_agent_urls containing: a2a_provider = A2AClientToolProvider(known_agent_urls=[ -# - "http://127.0.0.1:8000" (The Sage of Rules' tower) -# - "http://127.0.0.1:8001" (The Hall of Heroes) +# - "http://0.0.0.0:8000" (The Sage of Rules' tower) +# - "http://0.0.0.0:8001" (The Hall of Heroes) ]) ``` diff --git a/5_a2a_integration/agents/character_agent/character_agent.py b/5_a2a_integration/agents/character_agent/character_agent.py index 68218d0..0da6a0d 100644 --- a/5_a2a_integration/agents/character_agent/character_agent.py +++ b/5_a2a_integration/agents/character_agent/character_agent.py @@ -138,7 +138,6 @@ def create_character( characters_db.insert(asdict(character)) print("Inserted") - print(character) return character diff --git a/5_a2a_integration/agents/gamemaster_orchestrator/gamemaster_orchestrator.py b/5_a2a_integration/agents/gamemaster_orchestrator/gamemaster_orchestrator.py index 8cefc04..e8e993d 100644 --- a/5_a2a_integration/agents/gamemaster_orchestrator/gamemaster_orchestrator.py +++ b/5_a2a_integration/agents/gamemaster_orchestrator/gamemaster_orchestrator.py @@ -9,7 +9,8 @@ from fastapi.responses import JSONResponse from fastapi.middleware.cors import CORSMiddleware from pydantic import BaseModel -from strands_tools import generate_image + +from tinydb import TinyDB, Query # Load environment variables load_dotenv() @@ -39,11 +40,23 @@ def health_check(): def get_messages(): return agent.messages -# A2A Client for agent communication (workshop-compatible version) -a2a_provider = A2AClientToolProvider(known_agent_urls=[ - "http://127.0.0.1:8000", # Rules Agent - "http://127.0.0.1:8001", # Character Agent -]) +@app.get("/user/{user_name}") +def get_user(user_name): + characters_db = TinyDB('./../character_agent/characters.json') + Character_Query = Query() + result = characters_db.search(Character_Query.name == user_name) + if not result: + return f":x: Character with name '{user_name}' not found" + + character = result[0] + print(f"✅ Found character: {character['name']} (ID: {character['character_id']}, {character['character_class']} {character['race']})") + return character + +# TODO: Create A2A Client for agent communication +# Initialize A2AClientToolProvider with known_agent_urls containing: +# - "http://0.0.0.0:8000" (Rules Agent) +# - "http://0.0.0.0:8001" (Character Agent) +a2a_provider = None # Initialize A2A tools a2a_tools = list(a2a_provider.tools) if a2a_provider else [] @@ -51,9 +64,15 @@ def get_messages(): agent = Agent( model=os.getenv("MODEL_ID"), - tools=a2a_tools + [generate_image], + tools=a2a_tools, system_prompt="""You are a D&D Game Master orchestrator. You MUST always consult your specialized agents before responding. +CHARACTER CREATION REQUIREMENT: +BEFORE starting any game session, you MUST ensure the player has a character created and stored in the database: +1. Use a2a_send_message to ask the Character Agent (port 8001) to check if a character exists for this player +2. If no character exists, guide the player through character creation using the Character Agent +3. Only proceed with the game session AFTER confirming the character is created and stored in TinyDB + MANDATORY WORKFLOW: 1. FIRST: Use a2a_list_discovered_agents to see available agents 2. THEN: Use a2a_send_message to consult the appropriate agent(s) for the request @@ -89,12 +108,13 @@ def get_messages(): In the "details" of the json, provide the details of the tools and agents you used to generate the response -Remember, the response should ONLY be a PURE json with no markdown or text arount it +Remember, the response should ONLY be a PURE json with no markdown or text arount it. """ ) -# MCP Client for dice rolling service -mcp_dice_client = MCPClient(lambda: streamablehttp_client("http://localhost:8080/mcp")) +# TODO: Create MCP Client for dice rolling service +# Initialize MCPClient with a lambda that returns streamablehttp_client("http://localhost:8080/mcp") +mcp_dice_client = None # Add MCP tools to agent if mcp_dice_client: @@ -137,4 +157,6 @@ async def ask_agent(request: QuestionRequest): if __name__ == "__main__": - uvicorn.run(app, host="0.0.0.0", port=8009) + # TODO: Start the FastAPI server + # Use uvicorn.run() with app, host="0.0.0.0", and port=8009 + pass