Skip to content
Merged
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
15 changes: 12 additions & 3 deletions src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ function runAgentStream(input: AgentLoopInput): Stream.Stream<LLMEvent, Error> {
if (!hasToolCalls) {
const finalState: AgentLoopState = {
round: round + 1,
messageCount: history.length + 2,
messageCount: history.length,
toolCallCount,
lastFinishReason: finishReason,
hasToolCalls: false,
Expand Down Expand Up @@ -406,7 +406,7 @@ function runAgentStream(input: AgentLoopInput): Stream.Stream<LLMEvent, Error> {
// Model returned tool-calls finish reason but no valid tool calls — fire callback with stuck state
const stuckState: AgentLoopState = {
round: round + 1,
messageCount: history.length + 2,
messageCount: history.length,
toolCallCount,
lastFinishReason: finishReason,
hasToolCalls: false,
Expand Down Expand Up @@ -815,7 +815,16 @@ export const makeAgentLoop = Layer.effect(
}
}

// Max steps reached
// Max steps reached
const stateMax: AgentLoopState = {
round,
messageCount: history.length,
toolCallCount,
lastFinishReason,
hasToolCalls: false,
lastText,
}
if (input.onRound) { try { input.onRound(stateMax); } catch {} }
const response = buildResponse(lastEvents, accumulatedUsage)
return {
response,
Expand Down
Loading