|
41 | 41 | ) |
42 | 42 | from agent.utils import ( |
43 | 43 | anthropic_websearch_called, |
| 44 | + build_model_config, |
44 | 45 | get_all_tools, |
45 | 46 | get_api_key_for_model, |
46 | 47 | get_model_token_limit, |
@@ -78,12 +79,12 @@ async def clarify_with_user(state: AgentState, config: RunnableConfig) -> Comman |
78 | 79 |
|
79 | 80 | # Step 2: Prepare the model for structured clarification analysis |
80 | 81 | messages = state["messages"] |
81 | | - model_config = { |
82 | | - "model": configurable.research_model, |
83 | | - "max_tokens": configurable.research_model_max_tokens, |
84 | | - "api_key": get_api_key_for_model(configurable.research_model, config), |
85 | | - "tags": ["langsmith:nostream"] |
86 | | - } |
| 82 | + model_config = build_model_config( |
| 83 | + configurable.research_model, |
| 84 | + configurable.research_model_max_tokens, |
| 85 | + config, |
| 86 | + tags=["langsmith:nostream"] |
| 87 | + ) |
87 | 88 |
|
88 | 89 | # Configure model with structured output and retry logic |
89 | 90 | clarification_model = ( |
@@ -131,12 +132,12 @@ async def write_research_brief(state: AgentState, config: RunnableConfig) -> Com |
131 | 132 | """ |
132 | 133 | # Step 1: Set up the research model for structured output |
133 | 134 | configurable = Configuration.from_runnable_config(config) |
134 | | - research_model_config = { |
135 | | - "model": configurable.research_model, |
136 | | - "max_tokens": configurable.research_model_max_tokens, |
137 | | - "api_key": get_api_key_for_model(configurable.research_model, config), |
138 | | - "tags": ["langsmith:nostream"] |
139 | | - } |
| 135 | + research_model_config = build_model_config( |
| 136 | + configurable.research_model, |
| 137 | + configurable.research_model_max_tokens, |
| 138 | + config, |
| 139 | + tags=["langsmith:nostream"] |
| 140 | + ) |
140 | 141 |
|
141 | 142 | # Configure model for structured research question generation |
142 | 143 | research_model = ( |
@@ -191,12 +192,12 @@ async def supervisor(state: SupervisorState, config: RunnableConfig) -> Command[ |
191 | 192 | """ |
192 | 193 | # Step 1: Configure the supervisor model with available tools |
193 | 194 | configurable = Configuration.from_runnable_config(config) |
194 | | - research_model_config = { |
195 | | - "model": configurable.research_model, |
196 | | - "max_tokens": configurable.research_model_max_tokens, |
197 | | - "api_key": get_api_key_for_model(configurable.research_model, config), |
198 | | - "tags": ["langsmith:nostream"] |
199 | | - } |
| 195 | + research_model_config = build_model_config( |
| 196 | + configurable.research_model, |
| 197 | + configurable.research_model_max_tokens, |
| 198 | + config, |
| 199 | + tags=["langsmith:nostream"] |
| 200 | + ) |
200 | 201 |
|
201 | 202 | # Available tools: research delegation, completion signaling, and strategic thinking |
202 | 203 | lead_researcher_tools = [ConductResearch, ResearchComplete, think_tool] |
@@ -389,12 +390,12 @@ async def researcher(state: ResearcherState, config: RunnableConfig) -> Command[ |
389 | 390 | ) |
390 | 391 |
|
391 | 392 | # Step 2: Configure the researcher model with tools |
392 | | - research_model_config = { |
393 | | - "model": configurable.research_model, |
394 | | - "max_tokens": configurable.research_model_max_tokens, |
395 | | - "api_key": get_api_key_for_model(configurable.research_model, config), |
396 | | - "tags": ["langsmith:nostream"] |
397 | | - } |
| 393 | + research_model_config = build_model_config( |
| 394 | + configurable.research_model, |
| 395 | + configurable.research_model_max_tokens, |
| 396 | + config, |
| 397 | + tags=["langsmith:nostream"] |
| 398 | + ) |
398 | 399 |
|
399 | 400 | # Prepare system prompt with MCP context if available |
400 | 401 | researcher_prompt = research_system_prompt.format( |
@@ -524,12 +525,13 @@ async def compress_research(state: ResearcherState, config: RunnableConfig): |
524 | 525 | """ |
525 | 526 | # Step 1: Configure the compression model |
526 | 527 | configurable = Configuration.from_runnable_config(config) |
527 | | - synthesizer_model = configurable_model.with_config({ |
528 | | - "model": configurable.compression_model, |
529 | | - "max_tokens": configurable.compression_model_max_tokens, |
530 | | - "api_key": get_api_key_for_model(configurable.compression_model, config), |
531 | | - "tags": ["langsmith:nostream"] |
532 | | - }) |
| 528 | + compression_model_config = build_model_config( |
| 529 | + configurable.compression_model, |
| 530 | + configurable.compression_model_max_tokens, |
| 531 | + config, |
| 532 | + tags=["langsmith:nostream"] |
| 533 | + ) |
| 534 | + synthesizer_model = configurable_model.with_config(compression_model_config) |
533 | 535 |
|
534 | 536 | # Step 2: Prepare messages for compression |
535 | 537 | researcher_messages = state.get("researcher_messages", []) |
@@ -624,12 +626,12 @@ async def final_report_generation(state: AgentState, config: RunnableConfig): |
624 | 626 |
|
625 | 627 | # Step 2: Configure the final report generation model |
626 | 628 | configurable = Configuration.from_runnable_config(config) |
627 | | - writer_model_config = { |
628 | | - "model": configurable.final_report_model, |
629 | | - "max_tokens": configurable.final_report_model_max_tokens, |
630 | | - "api_key": get_api_key_for_model(configurable.final_report_model, config), |
631 | | - "tags": ["langsmith:nostream"] |
632 | | - } |
| 629 | + writer_model_config = build_model_config( |
| 630 | + configurable.final_report_model, |
| 631 | + configurable.final_report_model_max_tokens, |
| 632 | + config, |
| 633 | + tags=["langsmith:nostream"] |
| 634 | + ) |
633 | 635 |
|
634 | 636 | # Step 3: Attempt report generation with token limit retry logic |
635 | 637 | max_retries = 3 |
|
0 commit comments