everything is an agent

This commit is contained in:
Ramnique Singh 2025-11-15 01:51:22 +05:30
parent 2d6a647c70
commit 80dae17fd1
24 changed files with 1261 additions and 1573 deletions

View file

@ -1,28 +1,28 @@
import { z } from "zod";
export const BaseAgentTool = z.object({
export const BaseTool = z.object({
name: z.string(),
});
export const BuiltinAgentTool = BaseAgentTool.extend({
export const BuiltinTool = BaseTool.extend({
type: z.literal("builtin"),
});
export const McpAgentTool = BaseAgentTool.extend({
export const McpTool = BaseTool.extend({
type: z.literal("mcp"),
description: z.string(),
inputSchema: z.any(),
mcpServerName: z.string(),
});
export const WorkflowAgentTool = BaseAgentTool.extend({
type: z.literal("workflow"),
export const AgentAsATool = BaseTool.extend({
type: z.literal("agent"),
});
export const AgentTool = z.discriminatedUnion("type", [
BuiltinAgentTool,
McpAgentTool,
WorkflowAgentTool,
export const ToolAttachment = z.discriminatedUnion("type", [
BuiltinTool,
McpTool,
AgentAsATool,
]);
export const Agent = z.object({
@ -31,5 +31,5 @@ export const Agent = z.object({
model: z.string().optional(),
description: z.string(),
instructions: z.string(),
tools: z.record(z.string(), AgentTool).optional(),
tools: z.record(z.string(), ToolAttachment).optional(),
});

View file

@ -1,7 +1,7 @@
import { z } from "zod";
import { LlmStepStreamEvent } from "./llm-step-event.js";
import { Workflow } from "./workflow.js";
import { LlmStepStreamEvent } from "./llm-step-events.js";
import { Message } from "./message.js";
import { Agent } from "./agent.js";
const BaseRunEvent = z.object({
ts: z.iso.datetime().optional(),
@ -10,47 +10,39 @@ const BaseRunEvent = z.object({
export const RunStartEvent = BaseRunEvent.extend({
type: z.literal("start"),
runId: z.string(),
workflowId: z.string(),
workflow: Workflow,
agentId: z.string(),
agent: Agent,
interactive: z.boolean(),
});
export const RunStepStartEvent = BaseRunEvent.extend({
type: z.literal("step-start"),
stepIndex: z.number(),
stepId: z.string(),
stepType: z.enum(["agent", "function"]),
});
export const RunStreamEvent = BaseRunEvent.extend({
type: z.literal("stream-event"),
stepId: z.string(),
event: LlmStepStreamEvent,
});
export const RunMessageEvent = BaseRunEvent.extend({
type: z.literal("message"),
stepId: z.string(),
message: Message,
});
export const RunToolInvocationEvent = BaseRunEvent.extend({
type: z.literal("tool-invocation"),
stepId: z.string(),
toolName: z.string(),
input: z.string(),
});
export const RunToolResultEvent = BaseRunEvent.extend({
type: z.literal("tool-result"),
stepId: z.string(),
toolName: z.string(),
result: z.any(),
});
export const RunStepEndEvent = BaseRunEvent.extend({
type: z.literal("step-end"),
stepIndex: z.number(),
});
export const RunEndEvent = BaseRunEvent.extend({

View file

@ -1,21 +0,0 @@
import { z } from "zod";
const AgentStep = z.object({
type: z.literal("agent"),
id: z.string(),
});
const FunctionStep = z.object({
type: z.literal("function"),
id: z.string(),
});
export const Step = z.discriminatedUnion("type", [AgentStep, FunctionStep]);
export const Workflow = z.object({
name: z.string(),
description: z.string(),
steps: z.array(Step),
createdAt: z.string().optional(),
updatedAt: z.string().optional(),
});