From d25807a09bb7aedf45276ea99bbd3eb5c2d49a47 Mon Sep 17 00:00:00 2001 From: TheWitcherish Date: Mon, 8 Sep 2025 22:26:16 +0200 Subject: [PATCH] feat(messages): Added messages to be used by the frontend + user and player information --- 5_a2a_integration/README.md | 4 +-- .../agents/character_agent/character_agent.py | 1 - .../gamemaster_orchestrator.py | 30 ++++++++++++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) 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 df087c7..3b1cfd6 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 4a3163e..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() @@ -35,11 +36,26 @@ class QuestionRequest(BaseModel): def health_check(): return {"status": "healthy"} +@app.get("/messages") +def get_messages(): + return agent.messages + +@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://127.0.0.1:8000" (Rules Agent) -# - "http://127.0.0.1:8001" (Character Agent) +# - "http://0.0.0.0:8000" (Rules Agent) +# - "http://0.0.0.0:8001" (Character Agent) a2a_provider = None # Initialize A2A tools @@ -48,9 +64,15 @@ def health_check(): 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