Skip to content

[Bug] Team.add_learnings_to_context flag is never read; LearningMachine context is never injected into Team system prompt #7595

@denizmatsu

Description

@denizmatsu

Description

Team accepts add_learnings_to_context: bool = True as a parameter, but Team's system-message builder (agno/team/_messages.py) never reads this flag and never calls _learning.build_context() / abuild_context(). As a result, when LearningMachine stores a user profile (or any other learning store data) in DB, Team runs in later sessions cannot see it — the profile is never injected into the system prompt.

Agent handles this correctly: agno/agent/_messages.py:400-407 (sync) and :751-758 (async) both call agent._learning.build_context() / abuild_context() and append the result to system_message_content. Team has no equivalent hook.

This means write path works (the AGENTIC update_profile tool does save to DB), but read path is silently missing — the stored profile has no effect on subsequent sessions.

Steps to Reproduce

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.learn import LearningMachine, LearningMode, UserProfileConfig
from agno.models.openai import OpenAIResponses
from agno.team import Team

team_db = SqliteDb(db_file="tmp/teams.db")

team = Team(
    name="Learning Team",
    model=OpenAIResponses(id="gpt-5.2"),
    members=[Agent(name="Worker", model=OpenAIResponses(id="gpt-5.2"), role="Assist the user.")],
    db=team_db,
    learning=LearningMachine(
        user_profile=UserProfileConfig(mode=LearningMode.AGENTIC),
    ),
    markdown=True,
)

user_id = "team-learning-user"

# Session 1 — user shares info; AGENTIC update_profile tool writes to DB
team.print_response(
    "My name is Alex, and I prefer concise responses with bullet points.",
    user_id=user_id,
    session_id="session_1",
    stream=True,
)

# Verify DB write (profile row should exist):
#   SELECT * FROM agno_learnings
#   WHERE user_id='team-learning-user' AND learning_type='user_profile';

# Session 2 — ask what Team remembers
team.print_response(
    "What do you remember about how I prefer responses?",
    user_id=user_id,
    session_id="session_2",
    stream=True,
)

Swapping Team for Agent (with the same LearningMachine) makes session 2 work as expected, confirming the issue is specific to Team.

Agent Configuration (if applicable)

No response

Expected Behavior

In Session 2, the Team should respond with the stored profile information, e.g. "You're Alex, and you prefer concise responses with bullet points." This is what happens when the same setup is used with Agent instead of Team, because Agent injects learning.build_context() output into its system prompt (agno/agent/_messages.py:400-407 and :751-758).

Actual Behavior

In Session 2, the Team responds that it has no memory of the user / does not know their name. The profile row is present in the agno_learnings DB table (write path works), but Team never loads it into the system prompt, so the model has no awareness of it. The add_learnings_to_context=True flag has no effect.

Screenshots or Logs (if applicable)

No response

Environment

- agno version: **2.5.17** (latest at the time of this report); also reproducible on 2.5.9
- Python: 3.11
- OS: macOS 14
- DB: SqliteDb (also reproduced with PostgresDb / AsyncPostgresDb)
- Model: OpenAI gpt-5.2, also Google Gemini, also custom providers — model-independent

Possible Solutions (optional)

Mirror the Agent implementation in agno/team/_messages.py get_system_message / aget_system_message. Reference from Agent (agno/agent/_messages.py:400-407):

if team._learning is not None and team.add_learnings_to_context:
    learning_context = team._learning.build_context(  # or abuild_context in the async builder
        user_id=user_id,
        session_id=session.session_id if session else None,
        team_id=team.id,
    )
    if learning_context:
        system_message_content += learning_context + "\n"

Additional Context

Evidence that Team's message builder has no reference to _learning:

$ grep -rn "_learning\|\.learning" agno/team/*.py | grep -i "context\|build\|message\|prompt\|system"
agno/team/_init.py:156        → constructor param
agno/team/_init.py:346        → setter
agno/team/_storage.py:623-624 → serialize config
agno/team/_storage.py:956     → deserialize
agno/team/team.py:316         → dataclass field
agno/team/team.py:522         → __init__ param
agno/team/team.py:644         → __init__ forwarding
agno/team/_messages.py        → ❌ NO REFERENCE
  • team/_tools.py:177team._learning.get_tools() (AGENTIC tool expose — works)
  • team/_managers.pyteam._learning.aprocess() (ALWAYS write path — works)
  • team/_messages.py → no read/inject path (this is the missing piece)

Team get_system_message section comments (from agno/team/_messages.py:328):

2.1 Opening + team members + mode instructions
2.2 Identity sections: description, role, instructions
2.3 Knowledge base instructions
2.4 Memories           ← uses legacy team.memory_manager, NOT LearningMachine
2.5 Session summary
2.6 Trailing sections

No section invokes team._learning.build_context() — unlike Agent's section 3.3.12.

The cookbook example at cookbook/03_teams/memory/learning_machine.py is affected by this — its intended "session 2 recalls info from session 1" flow does not work because of this missing hookup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions