Skip to content

Commit b67af71

Browse files
Fix: Preserve context, session_state, and extra_data when creating default reasoning agents (#4081)
## Summary `Current Behavior:` When reasoning=True is used without specifying a reasoning model or agent, agno creates a default reasoning agent but loses the context, session_state, and extra_data from the original agent. As a result, these arguments are None when running the hooks. `Fix Implemented:` Added session_state, context, and extra_data arguments when creating default reasoning agents to preserve the original agent’s data. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Breaking change - [x] Improvement - [ ] Model update - [ ] Other: --- ## Checklist - [x] Code complies with style guidelines - [x] Ran format/validation scripts (`./scripts/format.sh` and `./scripts/validate.sh`) - [x] Self-review completed - [ ] Documentation updated (comments, docstrings) - [ ] Examples and guides: Relevant cookbook examples have been included or updated (if applicable) - [ ] Tested in clean environment - [ ] Tests added/updated (if applicable) --- ## Additional Notes Add any important context (deployment instructions, screenshots, security considerations, etc.)
1 parent deaa276 commit b67af71

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

libs/agno/agno/agent/agent.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5885,6 +5885,9 @@ def reason(self, run_messages: RunMessages) -> Iterator[RunResponseEvent]:
58855885
telemetry=self.telemetry,
58865886
debug_mode=self.debug_mode,
58875887
debug_level=self.debug_level,
5888+
session_state=self.session_state,
5889+
context=self.context,
5890+
extra_data=self.extra_data,
58885891
)
58895892
is_deepseek = is_deepseek_reasoning_model(reasoning_model)
58905893
is_groq = is_groq_reasoning_model(reasoning_model)
@@ -5974,6 +5977,9 @@ def reason(self, run_messages: RunMessages) -> Iterator[RunResponseEvent]:
59745977
telemetry=self.telemetry,
59755978
debug_mode=self.debug_mode,
59765979
debug_level=self.debug_level,
5980+
session_state=self.session_state,
5981+
context=self.context,
5982+
extra_data=self.extra_data,
59775983
)
59785984

59795985
# Validate reasoning agent
@@ -6108,6 +6114,9 @@ async def areason(self, run_messages: RunMessages) -> Any:
61086114
telemetry=self.telemetry,
61096115
debug_mode=self.debug_mode,
61106116
debug_level=self.debug_level,
6117+
session_state=self.session_state,
6118+
context=self.context,
6119+
extra_data=self.extra_data,
61116120
)
61126121
is_deepseek = is_deepseek_reasoning_model(reasoning_model)
61136122
is_groq = is_groq_reasoning_model(reasoning_model)
@@ -6197,6 +6206,9 @@ async def areason(self, run_messages: RunMessages) -> Any:
61976206
telemetry=self.telemetry,
61986207
debug_mode=self.debug_mode,
61996208
debug_level=self.debug_level,
6209+
session_state=self.session_state,
6210+
context=self.context,
6211+
extra_data=self.extra_data,
62006212
)
62016213

62026214
# Validate reasoning agent

libs/agno/agno/reasoning/default.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from textwrap import dedent
4-
from typing import Callable, Dict, List, Literal, Optional, Union
4+
from typing import Any, Callable, Dict, List, Literal, Optional, Union
55

66
from agno.models.base import Model
77
from agno.reasoning.step import ReasoningSteps
@@ -19,6 +19,9 @@ def get_default_reasoning_agent(
1919
telemetry: bool = True,
2020
debug_mode: bool = False,
2121
debug_level: Literal[1, 2] = 1,
22+
session_state: Optional[Dict[str, Any]] = None,
23+
context: Optional[Dict[str, Any]] = None,
24+
extra_data: Optional[Dict[str, Any]] = None,
2225
) -> Optional["Agent"]: # type: ignore # noqa: F821
2326
from agno.agent import Agent
2427

@@ -87,6 +90,9 @@ def get_default_reasoning_agent(
8790
telemetry=telemetry,
8891
debug_mode=debug_mode,
8992
debug_level=debug_level,
93+
session_state=session_state,
94+
context=context,
95+
extra_data=extra_data,
9096
)
9197

9298
agent.model.show_tool_calls = False # type: ignore

libs/agno/agno/reasoning/helpers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Literal
1+
from typing import Any, Dict, List, Literal, Optional
22

33
from agno.models.base import Model
44
from agno.models.message import Message
@@ -13,6 +13,9 @@ def get_reasoning_agent(
1313
telemetry: bool = False,
1414
debug_mode: bool = False,
1515
debug_level: Literal[1, 2] = 1,
16+
session_state: Optional[Dict[str, Any]] = None,
17+
context: Optional[Dict[str, Any]] = None,
18+
extra_data: Optional[Dict[str, Any]] = None,
1619
) -> "Agent": # type: ignore # noqa: F821
1720
from agno.agent import Agent
1821

@@ -22,6 +25,9 @@ def get_reasoning_agent(
2225
telemetry=telemetry,
2326
debug_mode=debug_mode,
2427
debug_level=debug_level,
28+
session_state=session_state,
29+
context=context,
30+
extra_data=extra_data,
2531
)
2632

2733

libs/agno/agno/team/team.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4504,7 +4504,11 @@ def _reason(
45044504
from agno.reasoning.openai import is_openai_reasoning_model
45054505

45064506
reasoning_agent = self.reasoning_agent or get_reasoning_agent(
4507-
reasoning_model=reasoning_model, monitoring=self.monitoring
4507+
reasoning_model=reasoning_model,
4508+
monitoring=self.monitoring,
4509+
session_state=self.session_state,
4510+
context=self.context,
4511+
extra_data=self.extra_data,
45084512
)
45094513
is_deepseek = is_deepseek_reasoning_model(reasoning_model)
45104514
is_groq = is_groq_reasoning_model(reasoning_model)
@@ -4597,6 +4601,9 @@ def _reason(
45974601
debug_mode=self.debug_mode,
45984602
debug_level=self.debug_level,
45994603
use_json_mode=use_json_mode,
4604+
session_state=self.session_state,
4605+
context=self.context,
4606+
extra_data=self.extra_data,
46004607
)
46014608

46024609
# Validate reasoning agent
@@ -4727,7 +4734,11 @@ async def _areason(
47274734
from agno.reasoning.openai import is_openai_reasoning_model
47284735

47294736
reasoning_agent = self.reasoning_agent or get_reasoning_agent(
4730-
reasoning_model=reasoning_model, monitoring=self.monitoring
4737+
reasoning_model=reasoning_model,
4738+
monitoring=self.monitoring,
4739+
session_state=self.session_state,
4740+
context=self.context,
4741+
extra_data=self.extra_data,
47314742
)
47324743
is_deepseek = is_deepseek_reasoning_model(reasoning_model)
47334744
is_groq = is_groq_reasoning_model(reasoning_model)
@@ -4818,6 +4829,9 @@ async def _areason(
48184829
debug_mode=self.debug_mode,
48194830
debug_level=self.debug_level,
48204831
use_json_mode=use_json_mode,
4832+
session_state=self.session_state,
4833+
context=self.context,
4834+
extra_data=self.extra_data,
48214835
)
48224836

48234837
# Validate reasoning agent

0 commit comments

Comments
 (0)