Memory Context Loss in Asynchronous Team Execution

I’ve encountered a critical issue when using the asynchronous execution mode with the Team class - historical context is not being preserved between consecutive calls, and the database tables for user memories are not being created.

Observed Behavior

  1. When executing multiple arun() calls on a Team instance, each call appears to execute in isolation without access to the conversation history from previous calls.
  2. Despite configuring a PostgreSQL database for memory storage, the user_memories table is not being created in the database.

Steps to Reproduce

# Setup memory with PostgreSQL backend
memory = Memory(
    model=AzureOpenAI(
        azure_deployment=deployment,
        azure_endpoint=endpoint,
        api_version=api_version,
        api_key=key
    ),
    db=PostgresMemoryDb(table_name="user_memories", db_url=db_url),
)

# Configure Team with the memory
agent_team = Team(
    mode="coordinate",
    members=[agent1, agent2],
    memory=memory,
    model=AzureOpenAI(...),
    storage=PostgresStorage(
        table_name="agent_sessions", 
        db_url=db_url, 
        auto_upgrade_schema=True
    ),
    enable_team_history=True,
    num_history_runs=1,
    session_id="1"
)

# Run multiple async queries
async def run_multiple_queries():
    # All queries use the same session_id and user_id
    await agent_team.arun(message1, stream=True, stream_intermediate_steps=True, session_id="1", user_id="dreamer")
    await agent_team.arun(message1, stream=True, stream_intermediate_steps=True, session_id="1", user_id="dreamer") 
    await agent_team.arun(message1, stream=True, stream_intermediate_steps=True, session_id="1", user_id="dreamer")
    await agent_team.arun(message1, stream=True, stream_intermediate_steps=True, session_id="1", user_id="dreamer")

# Execute in a single event loop
asyncio.run(run_multiple_queries())

Expected Behavior

  1. Each subsequent arun() call should have access to the conversation history from previous calls.
  2. The user_memories table should be automatically created in the PostgreSQL database.
  3. The conversation history should be persisted between calls, allowing agents to reference previous interactions.

Actual Behavior

  1. Each arun() call executes as if it’s the first interaction in the session - no history is preserved.
  2. The user_memories table is not created in the database.
  3. Despite using the same session_id and user_id, conversation continuity is lost.

Hi @Dreamer
thanks for reaching out and supporting Agno. I’ve shared this with the team, we’re working through all requests one by one and will get back to you soon.
If it’s urgent, please let us know. We appreciate your patience!

Would you please kindly inform the development team that this issue is urgent? We would greatly appreciate your prompt attention to this matter.

Hey @Dreamer
Sorry for the delay. @ayush from our team will quickly get back to you

hey @Dreamer can you please try again after passing this parameter to Team: enable_user_memories=True,

thanks and really sorry for late reply :raising_hands:

This parameter has been passed to the team when I tried to test the demo. The following is the setting of Team.
agent_team = Team(
mode=“coordinate”,
members=[agent1,agent2],
memory=memory,
model=AzureOpenAI(
azure_deployment=deployment,
azure_endpoint=endpoint,
api_version=api_version,
api_key=key
),
storage=PostgresStorage(
table_name=“agent_sessions”, db_url=db_url, auto_upgrade_schema=True
),
reasoning=False,
enable_team_history=True,
num_history_runs=3,
session_id=“1”,
enable_user_memories=True,
enable_agentic_memory=True
)

But my colleague didn’t encounter this problem when he used the local db. I think it may be the problem of the PostgreSQL db.
The memory seted as the follows:
memory = Memory(
# Use any model for creating memories
model=AzureOpenAI(
azure_deployment=deployment,
azure_endpoint=endpoint,
api_version=api_version,
api_key=key
),
db=PostgresMemoryDb(table_name=“user_memories”, db_url=db_url),
)