""" Tool registration pattern for CIRO agents. This module owns the *pattern* for tool registration, not the tools themselves. Each downstream phase ships its own tools: Phase 4 weather_api / social_feed Phase 8 maps_directions / dispatch_actions Phase 10 fcm_push / firestore_lookup …and registers them by exporting a `@function_tool`-decorated function from its module. The pipeline picks which subset to hand to each agent at call time (see `agents/pipeline.py`). There is intentionally no global tool registry — keeping the surface explicit per agent reduces the "which tool do I pick?" ambiguity that hurts model accuracy in multi-tool setups. Conventions every CIRO tool must follow --------------------------------------- 1. **Verb-first name.** `get_weather`, `fetch_routes`, `send_push` — not `weather` or `routes`. Verbs make the agent's tool-selection step unambiguous. 2. **Docstring shape: what / when / args / returns / errors.** The decorator feeds the docstring straight to the LLM as the tool description, so treat it as prompt engineering, not API docs. 3. **Return JSON strings, not Python objects.** The SDK serializes whatever you return, but explicit `json.dumps()` keeps the agent-visible payload deterministic and lets you embed `error` + `suggestion` fields for recovery (see `_ping_impl` below). 4. **Separate `_impl` from the decorated wrapper** for any tool with real business logic. Lets unit tests call `_impl` directly without going through the SDK. The dummy `ping` tool below is the reference implementation. Copy its shape when you add a real tool. """ import json from agents import function_tool # ── Reference dummy tool ────────────────────────────────────────────────── # # `ping` exists to (a) document the convention above and (b) give the Phase 3 # smoke test a deterministic tool to invoke without touching any external API. # Real tools (weather, maps, FCM) will replace it from their own modules. async def _ping_impl(message: str) -> str: """Pure logic for `ping` — separated so it can be unit-tested without going through the OpenAI Agents SDK. """ if not message: return json.dumps( { "error": "INVALID_INPUT", "message": "message must be a non-empty string", "suggestion": "Call ping again with a short non-empty message.", } ) return json.dumps({"echo": message, "status": "ok"}) @function_tool async def ping(message: str) -> str: """Echo a short message back. Reference tool used to verify the agent pipeline is wired up correctly. Use when: - You are explicitly asked to verify tool calling works. - You need a no-op tool to confirm an agent can invoke external code. Do NOT use this for any real crisis reasoning. Args: message: Any short non-empty string. The tool echoes it back verbatim. Returns: JSON string of the form `{"echo": "", "status": "ok"}`, or `{"error": "INVALID_INPUT", "message": ..., "suggestion": ...}` if `message` was empty. """ return await _ping_impl(message)