Skip to content

Refactor event loop to use Agent object rather than individual parameters #359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions src/strands/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
from opentelemetry import trace
from pydantic import BaseModel

from ..event_loop.event_loop import event_loop_cycle
from ..event_loop.event_loop import event_loop_cycle, run_tool
from ..experimental.hooks import AgentInitializedEvent, EndRequestEvent, HookRegistry, StartRequestEvent
from ..handlers.callback_handler import PrintingCallbackHandler, null_callback_handler
from ..handlers.tool_handler import AgentToolHandler
from ..models.bedrock import BedrockModel
from ..telemetry.metrics import EventLoopMetrics
from ..telemetry.tracer import get_tracer
Expand Down Expand Up @@ -130,14 +129,7 @@ def caller(
}

# Execute the tool
events = self._agent.tool_handler.process(
tool=tool_use,
model=self._agent.model,
system_prompt=self._agent.system_prompt,
messages=self._agent.messages,
tool_config=self._agent.tool_config,
kwargs=kwargs,
)
events = run_tool(agent=self._agent, tool=tool_use, kwargs=kwargs)

try:
while True:
Expand Down Expand Up @@ -283,7 +275,6 @@ def __init__(
self.load_tools_from_directory = load_tools_from_directory

self.tool_registry = ToolRegistry()
self.tool_handler = AgentToolHandler(tool_registry=self.tool_registry)

# Process tool list if provided
if tools is not None:
Expand Down Expand Up @@ -563,14 +554,7 @@ async def _execute_event_loop_cycle(self, kwargs: dict[str, Any]) -> AsyncGenera
try:
# Execute the main event loop cycle
events = event_loop_cycle(
model=self.model,
system_prompt=self.system_prompt,
messages=self.messages, # will be modified by event_loop_cycle
tool_config=self.tool_config,
tool_handler=self.tool_handler,
thread_pool=self.thread_pool,
event_loop_metrics=self.event_loop_metrics,
event_loop_parent_span=self.trace_span,
agent=self,
kwargs=kwargs,
)
async for event in events:
Expand Down
Loading