Skip to content

Commit b0b1d05

Browse files
authored
Merge branch 'main' into release-2.5.7
2 parents a0b5117 + 22af1a7 commit b0b1d05

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

libs/agno/agno/agent/_tools.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ def parse_tools(
376376
_function_names.append(name)
377377
_func = _func.model_copy(deep=True)
378378
_func._agent = agent
379+
if agent._team is not None:
380+
_func._team = agent._team
379381
# Respect the function's explicit strict setting if set
380382
effective_strict = strict if _func.strict is None else _func.strict
381383
_func.process_entrypoint(strict=effective_strict)
@@ -401,6 +403,8 @@ def parse_tools(
401403
tool.process_entrypoint(strict=effective_strict)
402404

403405
tool._agent = agent
406+
if agent._team is not None:
407+
tool._team = agent._team
404408
if strict and tool.strict is None:
405409
tool.strict = True
406410
if agent.tool_hooks is not None:
@@ -439,6 +443,8 @@ def parse_tools(
439443
)
440444
_func = _func.model_copy(deep=True)
441445
_func._agent = agent
446+
if agent._team is not None:
447+
_func._team = agent._team
442448
if strict:
443449
_func.strict = True
444450
if agent.tool_hooks is not None:

libs/agno/agno/agent/agent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ def __init__(
648648
self._cached_session: Optional[AgentSession] = None
649649

650650
self._tool_instructions: Optional[List[str]] = None
651+
self._team: Optional[Any] = None
651652

652653
self._formatter: Optional[SafeFormatter] = None
653654

libs/agno/agno/team/_init.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ def _initialize_member(team: "Team", member: Union["Team", Agent], debug_mode: O
465465

466466
if isinstance(member, Agent):
467467
member.team_id = team.id
468+
member._team = team
468469
member.set_id()
469470

470471
# Inherit team primary model if agent has no explicit model
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
from typing import Any
2+
from unittest.mock import MagicMock
3+
4+
from agno.agent.agent import Agent
5+
from agno.agent._tools import parse_tools
6+
from agno.tools.function import Function
7+
from agno.tools.toolkit import Toolkit
8+
9+
10+
def _mock_model():
11+
model = MagicMock()
12+
model.supports_native_structured_outputs = False
13+
return model
14+
15+
16+
def _mock_team():
17+
team = MagicMock()
18+
team.__class__.__name__ = "Team"
19+
return team
20+
21+
22+
# -- Callable tools ----------------------------------------------------------
23+
24+
25+
def test_callable_tool_receives_team_from_member_agent():
26+
def my_tool(query: str, team: Any) -> str:
27+
return "ok"
28+
29+
agent = Agent(tools=[my_tool])
30+
agent._team = _mock_team()
31+
32+
functions = parse_tools(agent=agent, tools=agent.tools, model=_mock_model())
33+
34+
assert len(functions) == 1
35+
assert functions[0]._team is agent._team
36+
37+
38+
def test_callable_tool_team_is_none_when_agent_has_no_team():
39+
def my_tool(query: str) -> str:
40+
return "ok"
41+
42+
agent = Agent(tools=[my_tool])
43+
44+
functions = parse_tools(agent=agent, tools=agent.tools, model=_mock_model())
45+
46+
assert len(functions) == 1
47+
assert functions[0]._team is None
48+
49+
50+
# -- Function objects ---------------------------------------------------------
51+
52+
53+
def test_function_tool_receives_team_from_member_agent():
54+
def my_tool(query: str, team: Any) -> str:
55+
return "ok"
56+
57+
func = Function.from_callable(my_tool)
58+
agent = Agent(tools=[func])
59+
agent._team = _mock_team()
60+
61+
functions = parse_tools(agent=agent, tools=agent.tools, model=_mock_model())
62+
63+
assert len(functions) == 1
64+
assert functions[0]._team is agent._team
65+
66+
67+
# -- Toolkit functions --------------------------------------------------------
68+
69+
70+
def test_toolkit_tool_receives_team_from_member_agent():
71+
class MyToolkit(Toolkit):
72+
def __init__(self):
73+
super().__init__(name="my_toolkit")
74+
self.register(self.my_tool)
75+
76+
def my_tool(self, query: str) -> str:
77+
return "ok"
78+
79+
agent = Agent(tools=[MyToolkit()])
80+
agent._team = _mock_team()
81+
82+
functions = parse_tools(agent=agent, tools=agent.tools, model=_mock_model())
83+
84+
toolkit_funcs = [f for f in functions if isinstance(f, Function)]
85+
assert len(toolkit_funcs) == 1
86+
assert toolkit_funcs[0]._team is agent._team

0 commit comments

Comments
 (0)