# Traditional approach - each step is a separate tool call
# Step 1: Search (tool call 1) search_results = agent.call_tool("search_salesforce", { "query":"active accounts", "fields": ["name","revenue","status"] }) # Returns 1000 records, all flow through context # Step 2: Filter (tool call 2) filtered_results = agent.call_tool("filter_records", { "data": search_results, # Passing large dataset through context "condition":"revenue > 1000000" }) # Filtered data flows back through context # Step 3: Summarize (tool call 3) summary = agent.call_tool("create_summary", { "data": filtered_results # More data through context }) # Total: 3 separate tool calls, all intermediate data through context
改进方案
代码执行方式:
1. Agent 编写导入 Salesforce 模块的代码
2. 代码在一次执行中搜索、过滤和汇总
3. 仅最终摘要返回给代理(可能是 500 个token)
以下是代理通过代码执行编写的内容:
// Code execution approach - single execution,allprocessinginenvironment
import{ salesforce }from'mcp-servers';
// Everything happensinthe execution environment asyncfunction getSalesforceSummary() { // Search const results =awaitsalesforce.search({ query:"active accounts", fields: ["name","revenue","status"] }); //1000records - but they never touch the model's context
// Filter (happens right here in code) const filtered = results.filter(record => record.revenue > 1000000); // Filtered to 50 records - still in execution environment
// Summarize (still in code) const summary = { total_accounts: filtered.length, total_revenue: filtered.reduce((sum, r) => sum + r.revenue, 0), top_account: filtered.sort((a, b) => b.revenue - a.revenue)[0] };
return summary; // Only this small object goes back to the model } // Agent gets back just the summary - maybe 100 tokens