Allow mocking tools over API and python sdk

This commit is contained in:
Ramnique Singh 2025-07-16 16:35:03 +05:30
parent c72728bf3d
commit 8ffdb66e0f
8 changed files with 54 additions and 18 deletions

View file

@ -51,6 +51,7 @@ export async function POST(
return Response.json({ error: `Invalid request body: ${result.error.message}` }, { status: 400 });
}
const reqMessages = result.data.messages;
const mockToolOverrides = result.data.mockTools;
// fetch published workflow id
const project = await projectsCollection.findOne({
@ -80,6 +81,11 @@ export async function POST(
return Response.json({ error: "Workflow not found" }, { status: 404 });
}
// override mock instructions
if (mockToolOverrides) {
workflow.mockTools = mockToolOverrides;
}
// check billing authorization
if (USE_BILLING && billingCustomerId) {
const agentModels = workflow.agents.reduce((acc, agent) => {

View file

@ -797,7 +797,13 @@ async function* emitGreetingTurn(logger: PrefixLogger, workflow: z.infer<typeof
function createTools(logger: PrefixLogger, workflow: z.infer<typeof Workflow>, toolConfig: Record<string, z.infer<typeof WorkflowTool>>): Record<string, Tool> {
const tools: Record<string, Tool> = {};
for (const [toolName, config] of Object.entries(toolConfig)) {
if (config.isMcp) {
if (workflow.mockTools?.[toolName]) {
tools[toolName] = createMockTool(logger, {
...config,
mockInstructions: workflow.mockTools?.[toolName], // override mock instructions
});
logger.log(`created mock tool: ${toolName}`);
} else if (config.isMcp) {
tools[toolName] = createMcpTool(logger, config, workflow.projectId);
logger.log(`created mcp tool: ${toolName}`);
} else if (config.isComposio) {

View file

@ -160,6 +160,7 @@ export const ApiRequest = z.object({
state: z.unknown(),
workflowId: z.string().nullable().optional(),
testProfileId: z.string().nullable().optional(),
mockTools: z.record(z.string(), z.string()).nullable().optional(),
});
export const ApiResponse = z.object({

View file

@ -69,6 +69,7 @@ export const Workflow = z.object({
createdAt: z.string().datetime(),
lastUpdatedAt: z.string().datetime(),
projectId: z.string(),
mockTools: z.record(z.string(), z.string()).optional(), // a dict of toolName => mockInstructions
});
export const WorkflowTemplate = Workflow
.omit({