- protocol.py: pydantic models for all AICC message types (envelope, session_init, tool_call, tool_result, event, error, heartbeat) - bridge.py: Bridge with @bridge.tool registration, capability checks, session management, serve_forever - client.py: AICCClient with single background reader (safe on concurrent transports like WebSocket), call_tool, events, manifest - tool.py: @tool decorator with schema generation from type hints - schema.py: JSON Schema generation (str/int/float/bool, list, dict, Optional, pydantic models) - transport: Transport protocol, InProcessTransport, WebSocket client+server - tests: 12 passing (integration, schema, websocket roundtrip) - examples: bridge_minimal.py + agent_minimal.py (verified end-to-end)
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
"""Minimal AICC bridge with a capsule in a room.
|
|
|
|
Run:
|
|
python examples/bridge_minimal.py
|
|
|
|
Then connect from another terminal:
|
|
python examples/agent_minimal.py
|
|
"""
|
|
|
|
import asyncio
|
|
|
|
from aicc import Bridge
|
|
from aicc.transport import WebSocketServer
|
|
|
|
|
|
async def main() -> None:
|
|
bridge = Bridge(name="capsule-room", kind="3d", tick_rate_hz=10.0)
|
|
|
|
@bridge.tool(description="Get the agent's current position and rotation.")
|
|
async def proprioception() -> dict:
|
|
return {
|
|
"position": {"x": 1.0, "y": 0.5, "z": 2.0},
|
|
"rotation": {"yaw": 0.0, "pitch": 0.0},
|
|
"velocity": {"x": 0.0, "y": 0.0, "z": 0.0},
|
|
"health": 100,
|
|
}
|
|
|
|
@bridge.tool(description="Move the agent forward by the given distance in meters.")
|
|
async def move(forward: float = 0.0) -> dict:
|
|
return {"moved": forward}
|
|
|
|
@bridge.tool(description="Turn the agent's heading by the given yaw angle in degrees.")
|
|
async def turn(yaw: float = 0.0) -> dict:
|
|
return {"turned": yaw}
|
|
|
|
print(f"AICC bridge '{bridge.name}' listening on ws://127.0.0.1:8765")
|
|
async with WebSocketServer(bridge, port=8765):
|
|
await bridge.serve_forever()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
asyncio.run(main())
|
|
except KeyboardInterrupt:
|
|
pass
|