Repository navigation
fix: add team_id filter to get_team_history for nested team support - #8956
Merged
harshsinha03 merged 6 commits intoJul 22, 2026
Merged
Conversation
get_team_history() and get_team_history_context() previously hardcoded the filter `parent_run_id is None`, which always returned only the top-level team's runs. In nested team scenarios where all runs share a single flat TeamSession.runs list, sub-teams could never retrieve their own history — they always received the root team's history instead. Changes: - Add optional `team_id` parameter to get_team_history() and get_team_history_context() in TeamSession - When team_id is provided, filter runs by run.team_id (uses getattr for safe access across TeamRunOutput/RunOutput types) - When team_id is None, preserve the original behavior (parent_run_id is None) for backward compatibility - Update delegation code in _default_tools.py and _task_tools.py to pass member team's id when the member is a Team, so sub-teams receive their own history context rather than the parent's - Add 3 integration tests covering team_id filtering, num_runs combination, and context formatting Fixes agno-agi#8954
harshsinha03
force-pushed
the
fix/get-team-history-nested-teams
branch
from
July 22, 2026 21:39
dfa4833 to
c5efc78
Compare
harshsinha03
approved these changes
Jul 22, 2026
harshsinha03
left a comment
Contributor
There was a problem hiding this comment.
LGTM! Thanks for contributing
Mustafa-Esoofally
pushed a commit
that referenced
this pull request
Jul 24, 2026
…8956) ## Summary `get_team_history()` and `get_team_history_context()` hardcode the filter `parent_run_id is None`, which always returns only the top-level team's runs. In nested team scenarios where all runs share a single flat `TeamSession.runs` list, sub-teams can never retrieve their own history — they always receive the root team's history instead. Fixes #8954 ## Changes - **`session/team.py`**: Add optional `team_id` parameter to `get_team_history()` and `get_team_history_context()`. When provided, filter runs by `run.team_id` (uses `getattr` for safe access across `TeamRunOutput`/`RunOutput` types). When `None`, preserve the original `parent_run_id is None` behavior. - **`_default_tools.py`**: Pass `member_team_id` to `get_team_history_context()` when the member is a Team, so sub-teams receive their own history context. - **`_task_tools.py`**: Same change for the task-based delegation path. - **`test_team_session.py`**: 3 new integration tests covering team_id filtering, team_id + num_runs combination, and context formatting. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Breaking change - [ ] Improvement - [ ] Model update - [ ] Other: ## Checklist - [x] Code follows the existing patterns (`get_messages()` already uses the same `team_id` filtering pattern) - [x] Tests pass locally (`11 passed, 0 failed`) - [x] `./scripts/format.sh` passes - [x] `./scripts/validate.sh` passes (ruff; mypy has a pre-existing pydantic_core env issue) - [x] Backward compatible — `team_id=None` preserves original behavior --------- Co-authored-by: Harsh <[email protected]> Co-authored-by: Harsh Sinha <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_team_history()andget_team_history_context()hardcode the filterparent_run_id is None, which always returns only the top-level team's runs. In nested team scenarios where all runs share a single flatTeamSession.runslist, sub-teams can never retrieve their own history — they always receive the root team's history instead.Fixes #8954
Changes
session/team.py: Add optionalteam_idparameter toget_team_history()andget_team_history_context(). When provided, filter runs byrun.team_id(usesgetattrfor safe access acrossTeamRunOutput/RunOutputtypes). WhenNone, preserve the originalparent_run_id is Nonebehavior._default_tools.py: Passmember_team_idtoget_team_history_context()when the member is a Team, so sub-teams receive their own history context._task_tools.py: Same change for the task-based delegation path.test_team_session.py: 3 new integration tests covering team_id filtering, team_id + num_runs combination, and context formatting.Type of change
Checklist
get_messages()already uses the sameteam_idfiltering pattern)11 passed, 0 failed)./scripts/format.shpasses./scripts/validate.shpasses (ruff; mypy has a pre-existing pydantic_core env issue)team_id=Nonepreserves original behavior