File size: 1,157 Bytes
a67fbf4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Example agents that ship with the system.
Register your own agents here or in separate modules.
"""
import asyncio
from typing import Any

from src.agents.base import AgentContext, BaseAgent
from src.agents.registry import AgentRegistry


@AgentRegistry.register("echo")
class EchoAgent(BaseAgent):
    """Returns whatever is passed as `message`."""

    async def execute(self, context: AgentContext, message: str = "hello", **kwargs) -> Any:
        return {"echo": message, "run_id": context.run_id}


@AgentRegistry.register("sleep")
class SleepAgent(BaseAgent):
    """Sleeps for `seconds` then returns elapsed time."""

    async def execute(self, context: AgentContext, seconds: float = 1.0, **kwargs) -> Any:
        await asyncio.sleep(seconds)
        return {"slept_seconds": seconds}


@AgentRegistry.register("compute")
class ComputeAgent(BaseAgent):
    """Performs a simple computation: sum of a list of numbers."""

    async def execute(self, context: AgentContext, numbers: list = None, **kwargs) -> Any:
        nums = numbers or [1, 2, 3, 4, 5]
        return {"sum": sum(nums), "count": len(nums), "average": sum(nums) / len(nums)}