:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(agent-platform): read the janitor's args_schema in tool schemas (#69202)
Aidan Zarskid9bda8977435
diff --git a/products/agent_platform/services/agent-runner/src/loop/build-agent-tools.test.ts b/products/agent_platform/services/agent-runner/src/loop/build-agent-tools.test.tsindex 3d218bbd22e3..9ff7b298a3fc 100644--- a/products/agent_platform/services/agent-runner/src/loop/build-agent-tools.test.ts+++ b/products/agent_platform/services/agent-runner/src/loop/build-agent-tools.test.ts@@ -15,6 +15,7 @@ import {S3BundleStore,ToolRefSchema,wipeTestPrefix,+ writeToolSourceAndSchema,} from '@posthog/agent-shared'import { AgentToolDeps, buildAgentTools } from './build-agent-tools'@@ -349,21 +350,27 @@ describe('buildAgentTools', () => {await expect(byId(built, 'fetch-acme').execute('c1', {})).rejects.toThrow(/requires a sandbox/)})- it('custom tool description + parameters load from schema.json in the bundle', async () => {+ it('custom tool parameters survive the writeToolSourceAndSchema → loadCustomSchema round-trip', async () => {+ // Author through the real writer (typed-bundle.ts writeToolSourceAndSchema)+ // rather than a hand-written fixture — the janitor's typed pipeline is the+ // sole production writer of schema.json and writes `{ description, args_schema }`,+ // so the runner reads that key and nothing else.const bundle = makeBundle()- await bundle.write(- 'rev1',- 'tools/fetch-acme/schema.json',- JSON.stringify({- description: 'Fetch from Acme',- args: { type: 'object', properties: { name: { type: 'string' } } },- })- )- const rev = makeRev([{ kind: 'custom', id: 'fetch-acme', path: 'tools/fetch-acme/' }])+ await writeToolSourceAndSchema('rev1', bundle, {+ id: 'add-numbers',+ description: 'Add two numbers',+ args_schema: { type: 'object', properties: { n: { type: 'number' } }, required: ['n'] },+ source: '// source',+ })+ const rev = makeRev([{ kind: 'custom', id: 'add-numbers', path: 'tools/add-numbers/' }])const built = await buildAgentTools(rev, makeDeps(rev, { bundle }))- const tool = byId(built, 'fetch-acme')- expect(tool.description).toBe('Fetch from Acme')- expect(tool.parameters).toEqual({ type: 'object', properties: { name: { type: 'string' } } })+ const tool = byId(built, 'add-numbers')+ expect(tool.description).toBe('Add two numbers')+ expect(tool.parameters).toEqual({+ type: 'object',+ properties: { n: { type: 'number' } },+ required: ['n'],+ })})describe('mcp tools', () => {diff --git a/products/agent_platform/services/agent-runner/src/loop/build-agent-tools.ts b/products/agent_platform/services/agent-runner/src/loop/build-agent-tools.tsindex ddb5a498005f..b001de12975c 100644--- a/products/agent_platform/services/agent-runner/src/loop/build-agent-tools.ts+++ b/products/agent_platform/services/agent-runner/src/loop/build-agent-tools.ts@@ -283,7 +283,7 @@ export async function buildAgentTools(rev: AgentRevision, deps: AgentToolDeps):continue}// custom — schema + description from the bundle, dispatched via sandbox.- const { description, parameters } = await loadCustomSchema(rev, t.id, t.path, deps.bundle)+ const { description, parameters } = await loadCustomSchema(rev, t.id, t.path, deps.bundle, deps.log)tools.push(makeCustomTool(t.id, description, parameters, deps, t.requires_identity))}@@ -614,17 +614,23 @@ async function loadCustomSchema(rev: AgentRevision,id: string,path: string,- bundle: BundleStore+ bundle: BundleStore,+ log: AgentToolDeps['log']): Promise<{ description: string; parameters: TSchema }> {const schemaPath = `${path.replace(/\/$/, '')}/schema.json`try {const raw = await bundle.readText(rev.id, schemaPath)- const schema = JSON.parse(raw) as { description?: string; args?: unknown }+ const schema = JSON.parse(raw) as { description?: string; args_schema?: unknown }+ const parameters = schema.args_schema as TSchema | undefined+ if (parameters == null) {+ log('warn', 'custom_tool.schema_missing_args_schema', { id, schemaPath })+ }return {description: schema.description ?? `custom tool ${id}`,- parameters: (schema.args as TSchema) ?? ({ type: 'object' } as unknown as TSchema),+ parameters: parameters ?? ({ type: 'object' } as unknown as TSchema),}- } catch {+ } catch (err) {+ log('warn', 'custom_tool.schema_unreadable', { id, schemaPath, err: (err as Error).message })return { description: `custom tool ${id}`, parameters: { type: 'object' } as unknown as TSchema }}}diff --git a/products/agent_platform/services/agent-tests/src/cases/approval-gated.test.ts b/products/agent_platform/services/agent-tests/src/cases/approval-gated.test.tsindex 7125fda3a795..f67b83bf3f23 100644--- a/products/agent_platform/services/agent-tests/src/cases/approval-gated.test.ts+++ b/products/agent_platform/services/agent-tests/src/cases/approval-gated.test.ts@@ -535,7 +535,7 @@ describe('approval-gated tools: real e2e', () => {'tools/echo-tool/compiled.js': COMPILED,'tools/echo-tool/schema.json': JSON.stringify({description: 'Echo',- args: { type: 'object', properties: { ping: { type: 'string' } } },+ args_schema: { type: 'object', properties: { ping: { type: 'string' } } },returns: { type: 'object' },}),},diff --git a/products/agent_platform/services/agent-tests/src/cases/custom-tool-sandbox.test.ts b/products/agent_platform/services/agent-tests/src/cases/custom-tool-sandbox.test.tsindex 781372b2abca..1614d0e9e2a4 100644--- a/products/agent_platform/services/agent-tests/src/cases/custom-tool-sandbox.test.ts+++ b/products/agent_platform/services/agent-tests/src/cases/custom-tool-sandbox.test.ts@@ -58,7 +58,7 @@ describe('custom tool sandbox: real e2e', () => {'tools/echoer/compiled.js': ECHOER_COMPILED,'tools/echoer/schema.json': JSON.stringify({description: 'echoes its input',- args: { type: 'object' },+ args_schema: { type: 'object' },}),},})@@ -121,7 +121,7 @@ describe('custom tool sandbox: real e2e', () => {'agent.md': 'echo agent','tools/echoer/source.ts': '// source','tools/echoer/compiled.js': ECHOER_COMPILED,- 'tools/echoer/schema.json': JSON.stringify({ description: 'echoes', args: { type: 'object' } }),+ 'tools/echoer/schema.json': JSON.stringify({ description: 'echoes', args_schema: { type: 'object' } }),},})const res = await request(c.ingress).post('/agents/tracked-agent/run').send({ message: 'fire' })diff --git a/products/agent_platform/services/agent-tests/src/cases/real-inference.test.ts b/products/agent_platform/services/agent-tests/src/cases/real-inference.test.tsindex 90304eeb4c52..f4aba32e66be 100644--- a/products/agent_platform/services/agent-tests/src/cases/real-inference.test.ts+++ b/products/agent_platform/services/agent-tests/src/cases/real-inference.test.ts@@ -325,7 +325,7 @@ maybeDescribe('real inference (via pi-ai): real e2e [%s]', (_label, real: Provid'tools/wordcount/compiled.js': COMPILED,'tools/wordcount/schema.json': JSON.stringify({description: 'Counts words in a string',- args: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'] },+ args_schema: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'] },}),},})@@ -520,7 +520,7 @@ maybeDescribe('real inference (via pi-ai): real e2e [%s]', (_label, real: Provid'tools/fetch-data/compiled.js': BOOM_TOOL,'tools/fetch-data/schema.json': JSON.stringify({description: 'Fetches data from the upstream service',- args: { type: 'object', properties: {} },+ args_schema: { type: 'object', properties: {} },}),},})diff --git a/products/agent_platform/services/agent-tests/src/cases/registry-templates.test.ts b/products/agent_platform/services/agent-tests/src/cases/registry-templates.test.tsindex 89b6e6e57674..ec4ab01098a0 100644--- a/products/agent_platform/services/agent-tests/src/cases/registry-templates.test.ts+++ b/products/agent_platform/services/agent-tests/src/cases/registry-templates.test.ts@@ -155,7 +155,7 @@ describe('registry-pinned templates: real e2e', () => {`,'tools/stripe_lookup/schema.json': JSON.stringify({description: 'Look up a customer by email',- args: {+ args_schema: {type: 'object',properties: { email: { type: 'string' } },required: ['email'],