Fix executionModel propagation on agent#1698
Conversation
|
executionModel propagation on agent
Greptile SummaryFixed Key Changes:
Impact: Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Agent Config with executionModel] --> B{executionModel type?}
B -->|string| C[Model name only]
B -->|AgentModelConfig| D[Full config with API keys]
C --> E[V3AgentHandler constructor]
D --> E
E --> F[createTools method]
F --> G[Pass executionModel to tools]
G --> H[act tool]
G --> I[extract tool]
G --> J[fillForm tool]
H --> K{Has executionModel?}
I --> K
J --> K
K -->|Yes| L[v3.act/extract/fillForm with model option]
K -->|No| M[Use default model]
L --> N[resolveLlmClient with full config]
N --> O[API key properly propagated]
style D fill:#90EE90
style O fill:#90EE90
style C fill:#FFB6C1
Last reviewed commit: 9557735 |
There was a problem hiding this comment.
No issues found across 7 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant User
participant V3 as V3 Orchestrator
participant Handler as V3AgentHandler
participant Tools as Agent Tools (Act/Extract/Fill)
participant Utils as ModelUtils
participant LLM as LLM Provider / Client
Note over User,LLM: Execution Model Propagation Flow
User->>V3: agent(options)
Note right of User: options include model and <br/>NEW: executionModel as AgentModelConfig
V3->>V3: resolveLlmClient(options.model)
V3->>Handler: NEW: Create Handler with executionModel (string | AgentModelConfig)
Handler->>Tools: NEW: Initialize Tools with executionModel config
Note over Tools,Utils: During Tool Execution (e.g., act, extract)
Tools->>Utils: extractModelName(executionModel)
Utils-->>Tools: Normalized model name string
Tools->>Utils: resolveModel(executionModel)
alt executionModel is AgentModelConfig
Utils->>Utils: Extract modelName
Utils->>Utils: CHANGED: Extract clientOptions (API Keys, Base URL)
else executionModel is string
Utils->>Utils: Use modelName
Utils->>Utils: Use default clientOptions (from ENV)
end
Utils-->>Tools: { clientOptions, modelName, isCua }
Tools->>LLM: Request completion
Note right of Tools: Uses specific clientOptions (API Keys)<br/>resolved for the executionModel provider
LLM-->>Tools: Tool Result
Tools-->>Handler: Action / Data
Handler-->>V3: Result
V3-->>User: Final Response
why
When passing an
executionModelto agent (for LLM-powered tools -- act, extract...) from a different provider than the one for the model provided in the Stagehand constructor, or in theAgentConfig, API keys are not propagating properly and causing errors in non-local environmentsThe root cause is the execution model was being passed as a string, and its respective API key doesn't propagate if explicitly defined. Unnoticeable if the API key for each provider is exported or in
.env, since we automatically pull when none is specified. This issue doesn't express itself if the different models share the same provider.what changed
test plan
Summary by cubic
Fix executionModel propagation by accepting either a string or AgentModelConfig across agent tools and the handler, and normalizing model names for correct resolution, API key usage, and telemetry.
Written for commit 0417e07. Summary will update on new commits. Review in cubic