|
| 1 | +"""Agent Interface. |
| 2 | +
|
| 3 | +Defines the minimal interface that all agent types must implement. |
| 4 | +""" |
| 5 | + |
| 6 | +from typing import Any, AsyncIterator, Protocol, runtime_checkable |
| 7 | + |
| 8 | +from ..types.agent import AgentInput |
| 9 | +from .agent_result import AgentResult |
| 10 | + |
| 11 | + |
| 12 | +@runtime_checkable |
| 13 | +class AgentBase(Protocol): |
| 14 | + """Protocol defining the interface for all agent types in Strands. |
| 15 | +
|
| 16 | + This protocol defines the minimal contract that all agent implementations |
| 17 | + must satisfy. |
| 18 | + """ |
| 19 | + |
| 20 | + async def invoke_async( |
| 21 | + self, |
| 22 | + prompt: AgentInput = None, |
| 23 | + **kwargs: Any, |
| 24 | + ) -> AgentResult: |
| 25 | + """Asynchronously invoke the agent with the given prompt. |
| 26 | +
|
| 27 | + Args: |
| 28 | + prompt: Input to the agent. |
| 29 | + **kwargs: Additional arguments. |
| 30 | +
|
| 31 | + Returns: |
| 32 | + AgentResult containing the agent's response. |
| 33 | + """ |
| 34 | + ... |
| 35 | + |
| 36 | + def __call__( |
| 37 | + self, |
| 38 | + prompt: AgentInput = None, |
| 39 | + **kwargs: Any, |
| 40 | + ) -> AgentResult: |
| 41 | + """Synchronously invoke the agent with the given prompt. |
| 42 | +
|
| 43 | + Args: |
| 44 | + prompt: Input to the agent. |
| 45 | + **kwargs: Additional arguments. |
| 46 | +
|
| 47 | + Returns: |
| 48 | + AgentResult containing the agent's response. |
| 49 | + """ |
| 50 | + ... |
| 51 | + |
| 52 | + def stream_async( |
| 53 | + self, |
| 54 | + prompt: AgentInput = None, |
| 55 | + **kwargs: Any, |
| 56 | + ) -> AsyncIterator[Any]: |
| 57 | + """Stream agent execution asynchronously. |
| 58 | +
|
| 59 | + Args: |
| 60 | + prompt: Input to the agent. |
| 61 | + **kwargs: Additional arguments. |
| 62 | +
|
| 63 | + Yields: |
| 64 | + Events representing the streaming execution. |
| 65 | + """ |
| 66 | + ... |
0 commit comments