Workflow doesn't work with Session Summaries

Hi,
I’ve already created a discussion topic in Github (Not sure if anyone actively monitoring it).

Git Issue: Issues with Session Summaries when using it with Workflow · agno-agi/agno · Discussion #5279 · GitHub

ISSUE:
The session summaries work fine when used with a standalone agent(Unable to add more than 1 Screenshot here, so please check the github link). However, when we try the same within a workflow, the summarization doesn’t get updated in the database (Screenshot) — even though the LLM performs the summarization (verified through debug logs).

This is critical because, in a workflow, summarization serves as the backbone for maintaining continuity and deriving context. Without it, we cannot inject large chat histories to retain the initial entity context.

Note: This use case is different from user memory. I want the workflow itself to retain awareness of entity context.

      session_id = "test_session_004"
      user_id = "test_user_001"
      query = input("Enter:")
      agent = Agent(
          model= AIModel.get_model(), # GPT-OSS Model
          db=AgnoDB.get_storage(), # MongoDB
          description="You are an assistant. Respond in very brief sentences. Mostly in one line",
          user_id=user_id,
          session_id=session_id,
          num_history_runs=1,
          enable_session_summaries=True
      )
      workflow = Workflow(
          user_id=user_id,
          session_id=session_id,
          steps=[Step(agent=agent)],
          add_workflow_history_to_steps=True
      )
      response = workflow.run(query)
      print(f"BOT: {response.content}")

DEBUG (1st Message)

DEBUG ****** Agent ID: 28c0ab95-1626-4f88-9ed8-964b0826ed48 ******              
DEBUG Creating new AgentSession: test_session_004                               
DEBUG ** Agent Run Start: 3c671a9c-191c-45e3-af98-1b177be31f57 ***              
DEBUG ------------------ OpenAI Response Start -------------------              
DEBUG ---------------- Model: openai/gpt-oss-120b ----------------              
DEBUG ========================== system ==========================              
DEBUG You are an assistant. Respond in very brief sentences. Mostly in one line 
DEBUG =========================== user ===========================              
DEBUG My name is Rafique                                                        
DEBUG ======================== assistant =========================              
DEBUG <reasoning>                                                               
      The user says "My name is Rafique". The system says respond in very brief 
      sentences, mostly one line. Probably acknowledge.                         
      </reasoning>                                                              
DEBUG Nice to meet you, Rafique.                                                
DEBUG ************************  METRICS  *************************              
DEBUG * Tokens:                      input=93, output=44, total=137             
DEBUG * Duration:                    1.0153s                                    
DEBUG * Tokens per second:           43.3351 tokens/s                           
DEBUG ************************  METRICS  *************************              
DEBUG ------------------- OpenAI Response End --------------------              
DEBUG Added RunOutput to Agent Session                                          
DEBUG ***************** Creating session summary *****************              
DEBUG ------------------ OpenAI Response Start -------------------              
DEBUG ---------------- Model: openai/gpt-oss-120b ----------------              
DEBUG ========================== system ==========================              
DEBUG Analyze the following conversation between a user and an assistant, and   
      extract the following details:                                            
      - Summary (str): Provide a concise summary of the session, focusing on    
      important information that would be helpful for future interactions.      
      - Topics (Optional[List[str]]): List the topics discussed in the session. 
      Keep the summary concise and to the point. Only include relevant          
      information.                                                              
      <conversation>User: My name is Rafique                                    
      Assistant: Nice to meet you, Rafique.                                     
      </conversation>                                                           
DEBUG =========================== user ===========================              
DEBUG Provide the summary of the conversation.                                  
DEBUG ======================== assistant =========================              
DEBUG <reasoning>                                                               
      We have a system prompt to "Analyze the following conversation between a  
      user and an assistant...". The user asks "Provide the summary of the      
      conversation." We must output JSON? The instruction says: "Provide a      
      concise summary of the session, focusing on important information... Keep 
      the summary concise and to the point. Only include relevant information." 
      It expects a structure:                                                   
      - Summary (str)                                                           
      - Topics (Optional[List[str]])                                            
                                                                                
      Probably JSON format. Many prior similar tasks require output like:       
      {                                                                         
        "Summary": "...",                                                       
        "Topics": [...]                                                         
      }                                                                         
      Thus we give summary: "User introduced themselves as Rafique, assistant   
      greeted them." Topics: maybe ["self-introduction", "greeting"]. Provide   
      concise.                                                                  
                                                                                
      Let's output JSON.                                                        
      </reasoning>                                                              
DEBUG {                                                                         
        "summary": "User introduced themselves as Rafique; the assistant        
      responded with a greeting.",                                              
        "topics": ["self-introduction", "greeting"]                             
      }                                                                         
DEBUG ************************  METRICS  *************************              
DEBUG * Tokens:                      input=175, output=190, total=365           
DEBUG * Duration:                    1.5015s                                    
DEBUG * Tokens per second:           126.5435 tokens/s                          
DEBUG ************************  METRICS  *************************              
DEBUG ------------------- OpenAI Response End --------------------              
DEBUG ***************** Session summary created ******************              
DEBUG Added RunOutput to Agent Session                                          
DEBUG *** Agent Run End: 3c671a9c-191c-45e3-af98-1b177be31f57 ****              
BOT: Nice to meet you, Rafique.

DEBUG (Last Message)

DEBUG ****** Agent ID: 451c5146-f659-431f-b5e0-3f094b2e02d3 ******              
DEBUG Creating new AgentSession: test_session_004                               
DEBUG ** Agent Run Start: 48df1b0c-d006-4578-a7e7-a07d7416648f ***              
DEBUG ------------------ OpenAI Response Start -------------------              
DEBUG ---------------- Model: openai/gpt-oss-120b ----------------              
DEBUG ========================== system ==========================              
DEBUG You are an assistant. Respond in very brief sentences. Mostly in one line 
DEBUG =========================== user ===========================              
DEBUG What's my name?                                                           
DEBUG ======================== assistant =========================              
DEBUG <reasoning>                                                               
      We can't answer because we don't know name; must be brief.                
      </reasoning>                                                              
DEBUG I don’t have that information.                                            
DEBUG ************************  METRICS  *************************              
DEBUG * Tokens:                      input=92, output=30, total=122             
DEBUG * Duration:                    0.8022s                                    
DEBUG * Tokens per second:           37.3979 tokens/s                           
DEBUG ************************  METRICS  *************************              
DEBUG ------------------- OpenAI Response End --------------------              
DEBUG Added RunOutput to Agent Session                                          
DEBUG ***************** Creating session summary *****************              
DEBUG ------------------ OpenAI Response Start -------------------              
DEBUG ---------------- Model: openai/gpt-oss-120b ----------------              
DEBUG ========================== system ==========================              
DEBUG Analyze the following conversation between a user and an assistant, and   
      extract the following details:                                            
      - Summary (str): Provide a concise summary of the session, focusing on    
      important information that would be helpful for future interactions.      
      - Topics (Optional[List[str]]): List the topics discussed in the session. 
      Keep the summary concise and to the point. Only include relevant          
      information.                                                              
      <conversation>User: What's my name?                                       
      Assistant: I don’t have that information.                                 
      </conversation>                                                           
DEBUG =========================== user ===========================              
DEBUG Provide the summary of the conversation.                                  
DEBUG ======================== assistant =========================              
DEBUG <reasoning>                                                               
      The user asks to provide summary of conversation. We need to output JSON  
      with fields Summary and Topics optional. The convo: User asked "What's my 
      name?" Assistant responded "I don’t have that information." So summary:   
      user asked for their name, assistant said doesn't have that info. Topics: 
      maybe "personal identification" or "name". Provide concise.               
      </reasoning>                                                              
DEBUG {                                                                         
        "summary": "The user asked for their name, and the assistant responded  
      that it does not have that information.",                                 
        "topics": ["personal identification", "name inquiry"]                   
      }                                                                         
DEBUG ************************  METRICS  *************************              
DEBUG * Tokens:                      input=172, output=119, total=291           
DEBUG * Duration:                    1.1865s                                    
DEBUG * Tokens per second:           100.2932 tokens/s                          
DEBUG ************************  METRICS  *************************              
DEBUG ------------------- OpenAI Response End --------------------              
DEBUG ***************** Session summary created ******************              
DEBUG Added RunOutput to Agent Session                                          
DEBUG *** Agent Run End: 48df1b0c-d006-4578-a7e7-a07d7416648f ****              
BOT: I don’t have that information.

SCREENSHOT:
Without Workflow:
(Check the github link above as i am unable to add more than 1 screenshot)

With Workflow:

PS: Documentations are good but not good enough. You should really update the documentation to cover the role of attributes and usage. For instance, I never knew that i have to enable add_workflow_history_to_steps to enable the history for the “Agents”, i thought add_history_to_context is enough to take care of it as i don’t need history for all the steps.

Hi @rafique, 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!

Hi Yuvi,

Thanks for the Prompt reply. This is sort of urgent. We are planning to integrate Agno in our Enterprise Application. If Agno Framework has issue at this level, then i am not sure if we could go ahead with Framework. I can understand your priorities, but to get me started, let me know the workarounds for this. I have to use Workflow for the sequential execution of the agent.

Hi @rafique ! Thanks for sharing the snippet! It looks like the Agent and the workflow are sharing the same `session_id`. So, what ends up happening is that the Agent Session gets overwritten by the Workflow Session after the Agent Run completes. Could you please try setting different `session_id` for both of them?

We really appreciate your feedback on the Docs. I agree that use add_workflow_history_to_steps is not as clear as it should be. We’ll work on i

Please let us know if there are any other issues you are facing or if you have any questions. Happy to resolve them on an urgent basis.

Thanks Yash,

Two things:

  1. I tried your ask, It is still not working. Please check screenshot

  2. What i don’t understand here is,

  • I am trying to save “summaries” which is generated by the “Agent” so agent has the db Access and an attribute enabled to save summaries, the agent will save the summaries using its own session_id? But In database i see that there is no session created for agent_session_002 but workflow wf_session_002 with the summary null
  • If Agent is not doing this but workflow then why there is NO enable_session_summaries_steps in the Workflow method?

Screenshot :

DB Screenshot for reference:

Thanks for sharing the snippets and more context.

When an Agent is used inside the context of a Workflow, it does not save its own Session. Rather, it contributes to the Workflows Session. Now, its a bug on our end that enables you to still create the Session Summary on an Agent level inside a Workflow and not be able to fetch it in any way. And I apologize for the earlier fix - setting different session_id would not resolve this issue. But I want to highlight that, inside a Workflow, an individual Agent Session does not persist. Only the Workflow Session does. So, a Session summary for any of the steps inside a Workflow is not a good pattern, since they are all technically part of the same session.

We have identified this gap where session summaries don’t work inside a Workflow. But, this would mean that all steps (Agents/Teams) inside a workflow would access the same session summary. We are working on this fix as first priority and thank you for highlighting it. Could you please share more about your use-case? I believe your use case could benefit from conversation workflows but would love to hear more.

You mentioned injecting large chat histories. Are there separate histories for each of the Agents run sequentially in your Workflow? Or a common base?

My apologies for the confusion, but I do want to make sure you are able to proceed with Agno and solve any issues you run into.

Yash,

Yes, I have seen the feature that was pushed in the recent release. It intrigued me at first, but again, it doesn’t have session summaries built in, which defeats the purpose. It’s essentially the same as a Workflow without a WF-Agent.

Let me explain a scenario at a high level:
The chatbot is responsible for handling queries across multiple contexts (30+). Each context contains hundreds of workflows, and each workflow supports turn-by-turn conversations. These conversations must persist state as long as the context remains unchanged.

To put it simply, let’s take an example:
When a user starts a new conversation, a session_id is generated. This session_id belongs only to the current conversation, regardless of the context the user switches to during the interaction.

User A → Tell me about the book harry potter Part 1 → Bot (sets summary Context:“Novel”,”title”:”Harry Potter”, entity:”Part1”) → Responds back with Part1 summarization

UserA → Who won the Quidditch match? → [Service → check classification → verifies if it is out-of-context or within “Novel” context → allows conversation to flow] → Bot ( has the entity which is Part 1 so it has to reply the result of part 1’s quidditch match, not part 2 or any other)

..conversation goes on for 10 times, The history injected here is always going to be 3 meaning it doesn’t know which part the conversation is all about but the session summary does, It has the entity information that the on-going conversation is all about Novel | Harry Potter |Part 1

UserA → Who won the Quidditch match in the Part 4? → Bot ( updates summary for entity:”Part4”) → Responds back

.. conversation goes on forever regarding Part 4 not Part 1 until the change of context happens from Novel to Documentary with different entities and topics.

Note: All these interactions belongs to one single session_id until user opens a “New Conversation”

Flow with usage of Workflow:

Here the workflow takes care of : Query Enrichment Agent(Requires summaries) → Context Check Agent(doesn’t require summaries) → Custom function to check previous step output and decides to exit the Workflow or not → Novel Agent(heavily requires summaries)

Hope this clarifies the complexity :slight_smile:

Thanks a lot for sharing @rafique. I really appreciate it. Could you please try the following config for the snippet you shared earlier:

from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.openai import OpenAIChat
from agno.workflow.step import Step
from agno.workflow.workflow import Workflow, Step, StepInput

db_url = "<your-db-url>"
db = PostgresDb(db_url=db_url, session_table="workflow_session")

def step_one_function(step_input: StepInput):
    agent = Agent(
        id="agent_001",
        db=db,
        model=OpenAIChat(id="gpt-5-mini"),
        add_history_to_context=True,
        enable_session_summaries=True,
    )
    return agent.run(input=step_input.input).content

step_one = Step(
    name="step_one",
    executor=step_one_function,
    description="Step one",
)

workflow = Workflow(
    session_id="test_session_001",
    steps=[step_one],
    db=db,
)
workflow.print_response(input="Hello, how are you?")

Through a custom executor, you can maintain a session for your Agent and create session summaries as required. This is different from using an Agent directly as a Workflow step. In that case the Agent contributes to the WF Session directly.

Though this looks like just a small part of your Workflow but this should help you achieve persistent session summaries on an Agent level. Please let me know if you have any other questions about the rest of your Workflow