Skip to content

Commit 7f38b3a

Browse files
authored
add stagehand agent to api (#1077)
# why Currently, we do not support stagehand agent within the api # what changed When api is enabled, stagehand agent now routes through the api # test plan Tested locally
1 parent bf2d0e7 commit 7f38b3a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

.changeset/loud-waves-think.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
adds support for stagehand agent in the api

lib/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,21 @@ export class Stagehand {
924924
"MCP integrations are an experimental feature. Please enable experimental mode by setting experimental: true in the Stagehand constructor params.",
925925
);
926926
}
927+
928+
const executeOptions: AgentExecuteOptions =
929+
typeof instructionOrOptions === "string"
930+
? { instruction: instructionOrOptions }
931+
: instructionOrOptions;
932+
933+
if (this.usingAPI) {
934+
const agentConfigForApi: AgentConfig = options;
935+
936+
return await this.apiClient.agentExecute(
937+
agentConfigForApi,
938+
executeOptions,
939+
);
940+
}
941+
927942
const tools = options?.integrations
928943
? await resolveTools(options?.integrations, options?.tools)
929944
: (options?.tools ?? {});
@@ -934,7 +949,7 @@ export class Stagehand {
934949
executionModel,
935950
systemInstructions,
936951
tools,
937-
).execute(instructionOrOptions);
952+
).execute(executeOptions);
938953
},
939954
};
940955
}

0 commit comments

Comments
 (0)