Skip to content

fix: add team_id filter to get_team_history for nested team support - #8956

Merged
harshsinha03 merged 6 commits into
agno-agi:mainfrom
SiAgentBuild:fix/get-team-history-nested-teams
Jul 22, 2026
Merged

harshsinha03 merged 6 commits into
agno-agi:mainfrom
SiAgentBuild:fix/get-team-history-nested-teams

Conversation

@SiAgentBuild

Copy link
Copy Markdown
Contributor

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

  • Bug fix
  • New feature
  • Breaking change
  • Improvement
  • Model update
  • Other:

Checklist

  • Code follows the existing patterns (get_messages() already uses the same team_id filtering pattern)
  • Tests pass locally (11 passed, 0 failed)
  • ./scripts/format.sh passes
  • ./scripts/validate.sh passes (ruff; mypy has a pre-existing pydantic_core env issue)
  • Backward compatible — team_id=None preserves original behavior

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
@SiAgentBuild
SiAgentBuild requested a review from a team as a code owner July 15, 2026 09:39
@harshsinha03
harshsinha03 force-pushed the fix/get-team-history-nested-teams branch from dfa4833 to c5efc78 Compare July 22, 2026 21:39

@harshsinha03 harshsinha03 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for contributing

@harshsinha03
harshsinha03 merged commit 1e03b4e into agno-agi:main Jul 22, 2026
11 checks passed
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]>
@SiAgentBuild
SiAgentBuild deleted the fix/get-team-history-nested-teams branch August 3, 2026 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] get_team_history() only looks at the top-level team

2 participants