Skip to content

Fix: Preserve context, session_state, and extra_data when creating default reasoning agents #4081

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
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
12 changes: 12 additions & 0 deletions libs/agno/agno/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5797,6 +5797,9 @@ def reason(self, run_messages: RunMessages) -> Iterator[RunResponseEvent]:
telemetry=self.telemetry,
debug_mode=self.debug_mode,
debug_level=self.debug_level,
session_state=self.session_state,
context=self.context,
extra_data=self.extra_data,
)
is_deepseek = is_deepseek_reasoning_model(reasoning_model)
is_groq = is_groq_reasoning_model(reasoning_model)
Expand Down Expand Up @@ -5886,6 +5889,9 @@ def reason(self, run_messages: RunMessages) -> Iterator[RunResponseEvent]:
telemetry=self.telemetry,
debug_mode=self.debug_mode,
debug_level=self.debug_level,
session_state=self.session_state,
context=self.context,
extra_data=self.extra_data,
)

# Validate reasoning agent
Expand Down Expand Up @@ -6020,6 +6026,9 @@ async def areason(self, run_messages: RunMessages) -> Any:
telemetry=self.telemetry,
debug_mode=self.debug_mode,
debug_level=self.debug_level,
session_state=self.session_state,
context=self.context,
extra_data=self.extra_data,
)
is_deepseek = is_deepseek_reasoning_model(reasoning_model)
is_groq = is_groq_reasoning_model(reasoning_model)
Expand Down Expand Up @@ -6109,6 +6118,9 @@ async def areason(self, run_messages: RunMessages) -> Any:
telemetry=self.telemetry,
debug_mode=self.debug_mode,
debug_level=self.debug_level,
session_state=self.session_state,
context=self.context,
extra_data=self.extra_data,
)

# Validate reasoning agent
Expand Down
8 changes: 7 additions & 1 deletion libs/agno/agno/reasoning/default.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from textwrap import dedent
from typing import Callable, Dict, List, Literal, Optional, Union
from typing import Any, Callable, Dict, List, Literal, Optional, Union

from agno.models.base import Model
from agno.reasoning.step import ReasoningSteps
Expand All @@ -19,6 +19,9 @@ def get_default_reasoning_agent(
telemetry: bool = True,
debug_mode: bool = False,
debug_level: Literal[1, 2] = 1,
session_state: Optional[Dict[str, Any]] = None,
context: Optional[Dict[str, Any]] = None,
extra_data: Optional[Dict[str, Any]] = None,
) -> Optional["Agent"]: # type: ignore # noqa: F821
from agno.agent import Agent

Expand Down Expand Up @@ -87,6 +90,9 @@ def get_default_reasoning_agent(
telemetry=telemetry,
debug_mode=debug_mode,
debug_level=debug_level,
session_state=session_state,
context=context,
extra_data=extra_data,
)

agent.model.show_tool_calls = False # type: ignore
Expand Down
8 changes: 7 additions & 1 deletion libs/agno/agno/reasoning/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Literal
from typing import Any, Dict, List, Literal, Optional

from agno.models.base import Model
from agno.models.message import Message
Expand All @@ -13,6 +13,9 @@ def get_reasoning_agent(
telemetry: bool = False,
debug_mode: bool = False,
debug_level: Literal[1, 2] = 1,
session_state: Optional[Dict[str, Any]] = None,
context: Optional[Dict[str, Any]] = None,
extra_data: Optional[Dict[str, Any]] = None,
) -> "Agent": # type: ignore # noqa: F821
from agno.agent import Agent

Expand All @@ -22,6 +25,9 @@ def get_reasoning_agent(
telemetry=telemetry,
debug_mode=debug_mode,
debug_level=debug_level,
session_state=session_state,
context=context,
extra_data=extra_data,
)


Expand Down
18 changes: 16 additions & 2 deletions libs/agno/agno/team/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -4305,7 +4305,11 @@ def _reason(
from agno.reasoning.openai import is_openai_reasoning_model

reasoning_agent = self.reasoning_agent or get_reasoning_agent(
reasoning_model=reasoning_model, monitoring=self.monitoring
reasoning_model=reasoning_model,
monitoring=self.monitoring,
session_state=self.session_state,
context=self.context,
extra_data=self.extra_data,
)
is_deepseek = is_deepseek_reasoning_model(reasoning_model)
is_groq = is_groq_reasoning_model(reasoning_model)
Expand Down Expand Up @@ -4398,6 +4402,9 @@ def _reason(
debug_mode=self.debug_mode,
debug_level=self.debug_level,
use_json_mode=use_json_mode,
session_state=self.session_state,
context=self.context,
extra_data=self.extra_data,
)

# Validate reasoning agent
Expand Down Expand Up @@ -4528,7 +4535,11 @@ async def _areason(
from agno.reasoning.openai import is_openai_reasoning_model

reasoning_agent = self.reasoning_agent or get_reasoning_agent(
reasoning_model=reasoning_model, monitoring=self.monitoring
reasoning_model=reasoning_model,
monitoring=self.monitoring,
session_state=self.session_state,
context=self.context,
extra_data=self.extra_data,
)
is_deepseek = is_deepseek_reasoning_model(reasoning_model)
is_groq = is_groq_reasoning_model(reasoning_model)
Expand Down Expand Up @@ -4619,6 +4630,9 @@ async def _areason(
debug_mode=self.debug_mode,
debug_level=self.debug_level,
use_json_mode=use_json_mode,
session_state=self.session_state,
context=self.context,
extra_data=self.extra_data,
)

# Validate reasoning agent
Expand Down