fix: aggregate tools across all steps

This commit is contained in:
Matt Rossman committed 2025-12-11 11:49:15 -05:00
1 parent 60e8b4a1d0
commit 7738cfc121
3 files changed
+45 -37

No files matched your search

+10 -5
View File
@@ -2,7 +2,7 @@ import { openai } from '@ai-sdk/openai'
import { Eval } from 'braintrust'
import { AssertionScorer } from 'lib/ai/evals/scorer'
import { generateAssistantResponse } from 'lib/ai/generate-assistant-response'
import { getMockTools } from 'lib/ai/tools'
import { getMockTools } from 'lib/ai/tools/mock-tools'
import assert from 'node:assert'
assert(process.env.BRAINTRUST_PROJECT_ID, 'BRAINTRUST_PROJECT_ID is not set')
@@ -29,12 +29,17 @@ Eval('Assistant', {
tools: await getMockTools(),
})
const text = await result.text
const toolCalls = await result.toolCalls
const textLastStep = await result.text
// `result.toolCalls` only shows the last step, instead aggregate tools across all steps
const steps = await result.steps
const toolNamesAllStepsFlattened = steps.flatMap((step) =>
step.toolCalls.map((call) => call.toolName)
)
return {
text: text,
tools: toolCalls.map((call) => call.toolName),
text: textLastStep,
tools: toolNamesAllStepsFlattened,
}
},
scores: [AssertionScorer],
-32
View File
@@ -58,35 +58,3 @@ export const getTools = async ({
return filteredTools
}
/**
* For evals
*/
export async function getMockTools() {
// Always include rendering tools
let tools: ToolSet = getRenderingTools()
const mcpTools = await getMcpTools({
accessToken: 'mock-access-token',
projectRef: 'mock-project-ref',
aiOptInLevel: 'schema_and_log_and_data',
})
// Override execute handlers for all MCP tools to return mock responses
const mockedMcpTools = Object.fromEntries(
Object.entries(mcpTools).map(([name, baseTool]) => [
name,
{
...baseTool,
execute: async () => ({ status: 'successful' }),
},
])
) as ToolSet
tools = {
...tools,
...mockedMcpTools,
}
return tools
}
+35
View File
@@ -0,0 +1,35 @@
import { ToolSet } from 'ai'
import { getMcpTools } from './mcp-tools'
import { getRenderingTools } from './rendering-tools'
/**
* For evals. See `index.ts` for the real tools
*/
export async function getMockTools() {
// Always include rendering tools
let tools: ToolSet = getRenderingTools()
const mcpTools = await getMcpTools({
accessToken: 'mock-access-token',
projectRef: 'mock-project-ref',
aiOptInLevel: 'schema_and_log_and_data',
})
// Override execute handlers for all MCP tools to return mock responses
const mockedMcpTools = Object.fromEntries(
Object.entries(mcpTools).map(([name, baseTool]) => [
name,
{
...baseTool,
execute: async () => ({ status: 'successful' }),
},
])
) as ToolSet
tools = {
...tools,
...mockedMcpTools,
}
return tools
}