Problem
When defining an agent with structured output, you currently have to use typeof Schema as the generic parameter:
const TriageSchema = z.object({
needs_updating: z.boolean(),
reason: z.string(),
});
type TriageResult = z.infer<typeof TriageSchema>;
// Awkward - have to use typeof Schema
export const triager = new Agent<RepoContext, typeof TriageSchema>({
output: TriageSchema,
});
This is unintuitive because the generic should represent what you get back, not the Zod machinery.
Desired API
// Clean - generic is the result type
export const triager = new Agent<RepoContext, TriageResult>({
output: TriageSchema,
});
Proposed Solution
- Change
AgentOutputType to represent result types instead of schema types:
// Before
export type AgentOutputType = TextOutput | ZodType;
// After
export type AgentResultType = string | Record<string, any>;
- Update config to accept
ZodType<TResult> for the output property:
interface AgentConfig<TContext, TResult = string> {
output?: ZodType<TResult>;
}
- Simplify
ResolvedAgentResponse to be identity:
// Before
export type ResolvedAgentResponse<TOutput extends AgentOutputType> =
TOutput extends TextOutput ? string : TOutput extends ZodType ? z.infer<TOutput> : never;
// After
export type ResolvedAgentResponse<TResult> = TResult;
Files to Update
packages/kernl/src/agent/types.ts
packages/kernl/src/guardrail.ts
packages/kernl/src/agent.ts
packages/kernl/src/agent/base.ts
packages/kernl/src/thread/thread.ts
packages/kernl/src/thread/types.ts
packages/kernl/src/thread/utils.ts
packages/kernl/src/kernl/kernl.ts
packages/kernl/src/lib/error.ts
packages/kernl/src/api/resources/agents/agents.ts
Problem
When defining an agent with structured output, you currently have to use
typeof Schemaas the generic parameter:This is unintuitive because the generic should represent what you get back, not the Zod machinery.
Desired API
Proposed Solution
AgentOutputTypeto represent result types instead of schema types:ZodType<TResult>for the output property:ResolvedAgentResponseto be identity:Files to Update
packages/kernl/src/agent/types.tspackages/kernl/src/guardrail.tspackages/kernl/src/agent.tspackages/kernl/src/agent/base.tspackages/kernl/src/thread/thread.tspackages/kernl/src/thread/types.tspackages/kernl/src/thread/utils.tspackages/kernl/src/kernl/kernl.tspackages/kernl/src/lib/error.tspackages/kernl/src/api/resources/agents/agents.ts