Skip to content

Commit bf2dbe4

Browse files
committed
feat(agent): introduce AgentBase Protocol as the interface for agent classes to implement
1 parent 8cae18c commit bf2dbe4

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

src/strands/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
from . import agent, models, telemetry, types
44
from .agent.agent import Agent
5+
from .agent.base import AgentBase
56
from .tools.decorator import tool
67
from .types.tools import ToolContext
78

89
__all__ = [
910
"Agent",
11+
"AgentBase",
1012
"agent",
1113
"models",
1214
"tool",

src/strands/agent/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from .agent import Agent
1010
from .agent_result import AgentResult
11+
from .base import AgentBase
1112
from .conversation_manager import (
1213
ConversationManager,
1314
NullConversationManager,
@@ -17,6 +18,7 @@
1718

1819
__all__ = [
1920
"Agent",
21+
"AgentBase",
2022
"AgentResult",
2123
"ConversationManager",
2224
"NullConversationManager",

src/strands/agent/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class _DefaultCallbackHandlerSentinel:
8989

9090

9191
class Agent:
92-
"""Core Agent interface.
92+
"""Core Agent implementation.
9393
9494
An agent orchestrates the following workflow:
9595

src/strands/agent/base.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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

Comments
 (0)