Skip to main content

I have one Agentforce requirement and would like to know the best approach.

My Agent has a Subagent with an Action. The Action calls a Flow, and the Flow is calling Invocable Apex to get Account-related data.

The Account can have many Contacts, Opportunities and Cases, sometimes even thousands of records.

I don’t want to send all these records back to Agentforce because it may increase token usage and also make the response too large.

So where is the best place to handle filtering and summarisation?

Should we handle it in:

  • Apex
  • Flow
  • Prompt Template
  • Agent Action output

Also, is it better to return structured data from Apex and allow Agentforce to summarise it, or should we prepare the final summary in Apex/Flow itself?

1 个回答
  1. 9月23日 05:45

    Hi Manohar, 

     

    In this case, I would try to reduce the data as much as possible before sending it to Agentforce. 

     

    For large data volumes, Apex is usually the better place to handle complex filtering, aggregation and record selection. Flow can be used mainly for orchestration, like calling Apex and passing the required result back to the Agent Action. 

     

    I would avoid sending thousands of raw Contacts, Opportunities or Cases directly to the LLM. Instead, return only the most relevant data, such as recent activities, open Cases, important Opportunities, counts and key findings. 

     

    A clean approach could be:

    Agentforce → Action → Flow → Apex → Filter/Aggregate Data → Return Small Structured Output → Agentforce/Prompt summarises it 

     

    I would also prefer returning structured data from Apex rather than generating the full natural-language response inside Apex. Apex should mainly handle business logic and data processing, while Agentforce or Prompt Builder can handle the final response. 

     

    This should help with scalability, token usage and overall maintainability. 

     

    Thank you, 

    Venkat Yadav.