Skip to content

Commit 72c617a

Browse files
committed
Implement STEP_TEXT within custom parsing within run-programmatic-step. Get best of n editor working!
1 parent b08c8f0 commit 72c617a

13 files changed

+680
-154
lines changed

.agents/editor/best-of-n/editor-best-of-n.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ function* handleStepsMax({
314314
)
315315

316316
// Spawn selector with implementations as params
317-
const { toolResult: selectorResult } = yield {
317+
const { toolResult: selectorResult, agentState: selectorAgentState } = yield {
318318
toolName: 'spawn_agents',
319319
input: {
320320
agents: [
@@ -353,27 +353,19 @@ function* handleStepsMax({
353353
return
354354
}
355355

356+
const numMessagesBeforeStepText = selectorAgentState.messageHistory.length
357+
356358
const { agentState: postEditsAgentState } = yield {
357359
type: 'STEP_TEXT',
358360
text: chosenImplementation.content,
359361
} as StepText
360362
const { messageHistory } = postEditsAgentState
361-
const lastAssistantMessageIndex = messageHistory.findLastIndex(
362-
(message) => message.role === 'assistant',
363-
)
364-
const editToolResults = messageHistory
365-
.slice(lastAssistantMessageIndex)
366-
.filter((message) => message.role === 'tool')
367-
.flatMap((message) => message.content)
368-
.filter((output) => output.type === 'json')
369-
.map((output) => output.value)
370363

371-
// Set output with the chosen implementation and reasoning
364+
// Set output with the messages from running the step text of the chosen implementation
372365
yield {
373366
toolName: 'set_output',
374367
input: {
375-
response: chosenImplementation.content,
376-
toolResults: editToolResults,
368+
messages: messageHistory.slice(numMessagesBeforeStepText),
377369
},
378370
includeToolCall: false,
379371
} satisfies ToolCall<'set_output'>

.agents/editor/best-of-n/editor-implementor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const createBestOfNImplementor = (options: {
3737
3838
Your task is to write out ALL the code changes needed to complete the user's request in a single comprehensive response.
3939
40-
Important: You can not make any other tool calls besides editing files. You cannot read more files, write todos, or spawn agents. Do not call any of these tools!
40+
Important: You can not make any other tool calls besides editing files. You cannot read more files, write todos, spawn agents, or set output. Do not call any of these tools!
4141
4242
Write out what changes you would make using the tool call format below. Use this exact format for each file change:
4343

evals/scaffolding.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ export async function runAgentStepScaffolding(
231231
signal: new AbortController().signal,
232232
spawnParams: undefined,
233233
system: 'Test system prompt',
234-
textOverride: null,
235234
tools: {},
236235
userId: TEST_USER_ID,
237236
userInputId: generateCompactId(),

packages/agent-runtime/src/__tests__/n-parameter.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ describe('n parameter and GENERATE_N functionality', () => {
104104
runAgentStepBaseParams = {
105105
...agentRuntimeImpl,
106106
additionalToolDefinitions: () => Promise.resolve({}),
107-
textOverride: null,
108107
runId: 'test-run-id',
109108
ancestorRunIds: [],
110109
repoId: undefined,

packages/agent-runtime/src/__tests__/read-docs-tool.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ describe('read_docs tool with researcher agent (via web API facade)', () => {
7575
runAgentStepBaseParams = {
7676
...agentRuntimeImpl,
7777
additionalToolDefinitions: () => Promise.resolve({}),
78-
textOverride: null,
7978
runId: 'test-run-id',
8079
ancestorRunIds: [],
8180
repoId: undefined,
@@ -215,7 +214,6 @@ describe('read_docs tool with researcher agent (via web API facade)', () => {
215214

216215
const { agentState: newAgentState } = await runAgentStep({
217216
...runAgentStepBaseParams,
218-
textOverride: null,
219217
fileContext: mockFileContextWithAgents,
220218
localAgentTemplates: agentTemplates,
221219
agentState,

packages/agent-runtime/src/__tests__/run-agent-step-tools.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ describe('runAgentStep - set_output tool', () => {
128128
signal: new AbortController().signal,
129129
spawnParams: undefined,
130130
system: 'Test system prompt',
131-
textOverride: null,
132131
tools: {},
133132
userId: TEST_USER_ID,
134133
userInputId: 'test-input',

packages/agent-runtime/src/__tests__/run-programmatic-step.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,6 @@ describe('runProgrammaticStep', () => {
15421542
const result = await runProgrammaticStep(mockParams)
15431543

15441544
expect(result.endTurn).toBe(false)
1545-
expect(result.textOverride).toBe('Custom response text')
15461545
expect(result.agentState.output?.error).toBeUndefined()
15471546
})
15481547

packages/agent-runtime/src/__tests__/web-search-tool.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ describe('web_search tool with researcher agent (via web API facade)', () => {
7474
signal: new AbortController().signal,
7575
spawnParams: undefined,
7676
system: 'Test system prompt',
77-
textOverride: null,
7877
tools: {},
7978
userId: TEST_USER_ID,
8079
userInputId: 'test-input',

packages/agent-runtime/src/prompt-agent-stream.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export const getAgentStreamFromTemplate = (params: {
2626
runId: string
2727
sessionConnections: SessionRecord
2828
template: AgentTemplate
29-
textOverride: string | null
3029
tools: ToolSet
3130
userId: string | undefined
3231
userInputId: string
@@ -48,7 +47,6 @@ export const getAgentStreamFromTemplate = (params: {
4847
runId,
4948
sessionConnections,
5049
template,
51-
textOverride,
5250
tools,
5351
userId,
5452
userInputId,
@@ -59,14 +57,6 @@ export const getAgentStreamFromTemplate = (params: {
5957
trackEvent,
6058
} = params
6159

62-
if (textOverride !== null) {
63-
async function* stream(): ReturnType<PromptAiSdkStreamFn> {
64-
yield { type: 'text', text: textOverride!, agentId }
65-
return crypto.randomUUID()
66-
}
67-
return stream()
68-
}
69-
7060
if (!template) {
7161
throw new Error('Agent template is null/undefined')
7262
}

packages/agent-runtime/src/run-agent-step.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,6 @@ export async function loopAgentSteps(
526526
| 'runId'
527527
| 'spawnParams'
528528
| 'system'
529-
| 'textOverride'
530529
| 'tools'
531530
> &
532531
ParamsExcluding<
@@ -716,7 +715,6 @@ export async function loopAgentSteps(
716715
const startTime = new Date()
717716

718717
// 1. Run programmatic step first if it exists
719-
let textOverride = null
720718
let n: number | undefined = undefined
721719

722720
if (agentTemplate.handleSteps) {
@@ -744,7 +742,6 @@ export async function loopAgentSteps(
744742
stepNumber,
745743
generateN,
746744
} = programmaticResult
747-
textOverride = programmaticResult.textOverride
748745
n = generateN
749746

750747
currentAgentState = programmaticAgentState
@@ -808,7 +805,6 @@ export async function loopAgentSteps(
808805
runId,
809806
spawnParams: currentParams,
810807
system,
811-
textOverride: textOverride,
812808
tools,
813809

814810
additionalToolDefinitions: async () => {

0 commit comments

Comments
 (0)