File size: 3,325 Bytes
1ffd0a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
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": "<message>", "status": "ok"}`,
        or `{"error": "INVALID_INPUT", "message": ..., "suggestion": ...}`
        if `message` was empty.
    """
    return await _ping_impl(message)