feat(agent): propagate autofill context from chat to autofill workflow

Add an optional 'context' parameter to the create_file and create_version
agent tools so the chat agent can pass generation/source context (e.g.
'Generated using gemini') to the AI metadata autofill workflow.

- Add Asset.autofillContext column, persisted in the same transaction as
  asset creation when context is provided
- Add new list_autofill_fields agent tool exposing autofillable metadata
  fields (name, type, description, options) per project
- Autofill workflow reads the stored context and includes it in the
  autofill AI prompt
- Add short chat system-prompt guidance to use list_autofill_fields and
  pass <=50 word context when creating files/versions
This commit is contained in:
yiling
2026-08-05 10:33:02 +08:00
parent 30021b07d0
commit 033652cde3
18 changed files with 905 additions and 7 deletions
@@ -20,6 +20,7 @@ describe.each(['local', 'temporal'] as const)(
let agentWorkerPromise: Promise<void> | null = null
let transcodeWorkerPromise: Promise<void> | null = null
let lastAutofillPrompt = ''
beforeAll(async () => {
// Set bucket environment
@@ -35,7 +36,11 @@ describe.each(['local', 'temporal'] as const)(
// Spy on the harness prompt method to intercept the LLM call while running real activities & tools
vi.spyOn(AgentHarness.prototype, 'prompt').mockImplementation(async function (
this: AgentHarness,
...args: unknown[]
) {
// Capture the prompt to verify agent-provided context is propagated
lastAutofillPrompt = typeof args[0] === 'string' ? args[0] : ''
// Find the real autofill_metadata tool configured on the harness
const tools = this.getTools()
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Tool execution mock for E2E harness test
@@ -239,6 +244,7 @@ describe.each(['local', 'temporal'] as const)(
mediaType: 'image/png',
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- partial MediaInfo mock for testing
media: { proxyType: 'image' } as any,
autofillContext: 'Generated using gemini',
projectId: project.id,
storageKeyId: storageKey.id,
},
@@ -278,6 +284,10 @@ describe.each(['local', 'temporal'] as const)(
// 5. Verification
expect(completedTask.status).toBe('completed')
// Verify the agent-provided autofill context was included in the LLM prompt
expect(lastAutofillPrompt).toContain('Generated using gemini')
expect(lastAutofillPrompt).toContain('<context>')
// Verify placeholder comment is updated correctly
const comments = await prisma.assetComment.findMany({
where: { assetId: asset.id },