Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/handlers/stagehandAgentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class StagehandAgentHandler {
? { instruction: instructionOrOptions }
: instructionOrOptions;

const maxSteps = options.maxSteps || 10;
const maxSteps = options.maxSteps || 20;
const actions: AgentAction[] = [];
let finalMessage = "";
let completed = false;
Expand Down Expand Up @@ -88,6 +88,8 @@ export class StagehandAgentHandler {
},
});

let stepNumber = 0;

const result = await this.llmClient.generateText({
model: wrappedModel,
system: systemPrompt,
Expand All @@ -99,8 +101,8 @@ export class StagehandAgentHandler {
onStepFinish: async (event) => {
this.logger({
category: "agent",
message: `Step finished: ${event.finishReason}`,
level: 2,
message: `Taking step ${++stepNumber}/${maxSteps}`,
level: 1,
});

if (event.toolCalls && event.toolCalls.length > 0) {
Expand All @@ -114,6 +116,12 @@ export class StagehandAgentHandler {
category: "agent",
message: `reasoning: ${event.text}`,
level: 1,
auxiliary: {
toolCalls: {
value: JSON.stringify(event.toolCalls),
type: "object",
},
},
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ export class Stagehand {
: instructionOrOptions;

if (this.usingAPI) {
const agentConfigForApi: AgentConfig = options;
const agentConfigForApi: AgentConfig = options ?? {};

return await this.apiClient.agentExecute(
agentConfigForApi,
Expand Down