@deepagents/agent 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +916 -0
- package/dist/index.js.map +7 -0
- package/dist/lib/agent.d.ts +100 -0
- package/dist/lib/agent.d.ts.map +1 -0
- package/dist/lib/blog/deepagents.d.ts +12 -0
- package/dist/lib/blog/deepagents.d.ts.map +1 -0
- package/dist/lib/blog/docker.d.ts +4 -0
- package/dist/lib/blog/docker.d.ts.map +1 -0
- package/dist/lib/blog/mesh.d.ts +4 -0
- package/dist/lib/blog/mesh.d.ts.map +1 -0
- package/dist/lib/blog/package-star.d.ts +4 -0
- package/dist/lib/blog/package-star.d.ts.map +1 -0
- package/dist/lib/blog/research.d.ts +4 -0
- package/dist/lib/blog/research.d.ts.map +1 -0
- package/dist/lib/blog/star.d.ts +4 -0
- package/dist/lib/blog/star.d.ts.map +1 -0
- package/dist/lib/examples/animated_svg.d.ts +2 -0
- package/dist/lib/examples/animated_svg.d.ts.map +1 -0
- package/dist/lib/examples/finanicals_bot.d.ts +2 -0
- package/dist/lib/examples/finanicals_bot.d.ts.map +1 -0
- package/dist/lib/examples/plan_and_act_example.d.ts +2 -0
- package/dist/lib/examples/plan_and_act_example.d.ts.map +1 -0
- package/dist/lib/examples/planner.d.ts +15 -0
- package/dist/lib/examples/planner.d.ts.map +1 -0
- package/dist/lib/examples/research_bot.d.ts +2 -0
- package/dist/lib/examples/research_bot.d.ts.map +1 -0
- package/dist/lib/memory.d.ts +701 -0
- package/dist/lib/memory.d.ts.map +1 -0
- package/dist/lib/models.d.ts +7 -0
- package/dist/lib/models.d.ts.map +1 -0
- package/dist/lib/patterns/plan_and_act/plan_and_act.d.ts +56 -0
- package/dist/lib/patterns/plan_and_act/plan_and_act.d.ts.map +1 -0
- package/dist/lib/patterns/plan_and_execute/plan_and_execute.d.ts +3 -0
- package/dist/lib/patterns/plan_and_execute/plan_and_execute.d.ts.map +1 -0
- package/dist/lib/patterns/plan_and_execute/plan_and_execute_os.d.ts +2 -0
- package/dist/lib/patterns/plan_and_execute/plan_and_execute_os.d.ts.map +1 -0
- package/dist/lib/patterns/plan_and_execute/plan_and_execute_supervisor.d.ts +2 -0
- package/dist/lib/patterns/plan_and_execute/plan_and_execute_supervisor.d.ts.map +1 -0
- package/dist/lib/patterns/plan_and_execute/plan_and_execute_triage.d.ts +2 -0
- package/dist/lib/patterns/plan_and_execute/plan_and_execute_triage.d.ts.map +1 -0
- package/dist/lib/patterns/rewoo/rewoo.d.ts +64 -0
- package/dist/lib/patterns/rewoo/rewoo.d.ts.map +1 -0
- package/dist/lib/patterns/supervisor.d.ts +12 -0
- package/dist/lib/patterns/supervisor.d.ts.map +1 -0
- package/dist/lib/prompts.d.ts +3 -0
- package/dist/lib/prompts.d.ts.map +1 -0
- package/dist/lib/rag.d.ts +2 -0
- package/dist/lib/rag.d.ts.map +1 -0
- package/dist/lib/stream_utils.d.ts +26 -0
- package/dist/lib/stream_utils.d.ts.map +1 -0
- package/dist/lib/swarm.d.ts +23 -0
- package/dist/lib/swarm.d.ts.map +1 -0
- package/dist/lib/visualize.d.ts +32 -0
- package/dist/lib/visualize.d.ts.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lib/agent.ts", "../src/lib/prompts.ts", "../src/lib/stream_utils.ts", "../src/lib/visualize.ts", "../src/lib/swarm.ts", "../src/lib/models.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n type GenerateTextResult,\n type LanguageModel,\n type ModelMessage,\n Output,\n type StreamTextResult,\n type Tool,\n type ToolChoice,\n type UIDataTypes,\n type UIMessage,\n type UITools,\n dynamicTool,\n generateText,\n jsonSchema,\n stepCountIs,\n tool,\n} from 'ai';\nimport chalk from 'chalk';\nimport { snakecase } from 'stringcase';\nimport z from 'zod';\n\nimport {\n RECOMMENDED_PROMPT_PREFIX,\n SUPERVISOR_PROMPT_PREFIX,\n} from './prompts.ts';\nimport { toState } from './stream_utils.ts';\nimport { prepareStep } from './swarm.ts';\n\nexport interface Handoff<C> {\n name: string;\n instructions: Instruction<C>;\n handoffDescription?: string;\n tools: Record<string, Tool>;\n}\nexport type Handoffs<C> = (Agent<unknown, C> | (() => Agent<unknown, C>))[];\n\nexport type Runner<T, C> = (\n prompt: string,\n agent: Agent<C>,\n messages: ModelMessage[],\n) => Promise<T>;\n\ntype transfer_tool = `transfer_to_${string}`;\n\nexport type ContextVariables = Record<string, unknown>;\n\nexport function agent<Output, C = ContextVariables>(\n config: CreateAgent<Output, C>,\n): Agent<Output, C> {\n return new Agent<Output, C>(config);\n}\n\nexport type ResponseMessage = UIMessage<unknown, UIDataTypes, UITools>;\n\nexport type AgentModel = Exclude<LanguageModel, string>;\nexport type OutputExtractorFn = (\n output: GenerateTextResult<Record<string, Tool>, any>,\n) => string | Promise<string>;\nexport type PrepareHandoffFn = (\n messages: ModelMessage[],\n) => void | Promise<void>;\nexport type PrepareEndFn<C> = (config: {\n messages: ResponseMessage[];\n responseMessage: ResponseMessage;\n contextVariables: C;\n abortSignal?: AbortSignal;\n}) => StreamTextResult<Record<string, Tool>, any> | undefined | void;\n\nexport interface CreateAgent<Output, C> {\n name: string;\n prompt: Instruction<C>;\n temperature?: number;\n handoffDescription?: string;\n prepareHandoff?: PrepareHandoffFn;\n prepareEnd?: PrepareEndFn<C>;\n handoffs?: Handoffs<C>;\n tools?: Record<string, Tool>;\n model: AgentModel;\n toolChoice?: ToolChoice<Record<string, unknown>>;\n output?: z.Schema<Output>;\n}\nexport class Agent<Output = unknown, C = ContextVariables> {\n model: AgentModel;\n toolChoice: ToolChoice<Record<string, unknown>> | undefined;\n parent?: Agent<unknown, C>;\n handoffs: Handoffs<C>;\n readonly prepareHandoff?: PrepareHandoffFn;\n readonly prepareEnd?: PrepareEndFn<C>;\n readonly internalName: string;\n readonly handoff: Handoff<C>;\n readonly handoffToolName: transfer_tool;\n readonly handoffTool: Record<string, Tool>;\n readonly output?: z.Schema<Output>;\n readonly temperature?: number;\n constructor(config: CreateAgent<Output, C>) {\n this.model = config.model;\n this.toolChoice = config.toolChoice || 'auto';\n this.handoffs = config.handoffs ?? [];\n this.prepareHandoff = config.prepareHandoff;\n this.prepareEnd = config.prepareEnd;\n this.output = config.output;\n this.temperature = config.temperature;\n this.internalName = snakecase(config.name);\n this.handoff = {\n name: this.internalName,\n instructions: config.prompt,\n tools: config.tools ?? {},\n handoffDescription: config.handoffDescription,\n };\n this.handoffToolName = `transfer_to_${this.internalName}`;\n this.handoffTool = {\n [this.handoffToolName]: dynamicTool({\n description: [\n `An input/parameter/argument less tool to transfer control to the ${this.internalName} agent.`,\n // `Handoff to the ${this.internalName} agent to handle the request`,\n // `Do not include any parameters/inputs. The agent have access to all the context it needs.`,\n config.handoffDescription,\n ]\n .filter(Boolean)\n .join(' '),\n inputSchema: jsonSchema({\n type: 'object',\n properties: {},\n additionalProperties: true,\n }),\n execute: async (_, options) => {\n const state = toState(options) as any;\n state.currentActiveAgent = this.internalName;\n return `Transfer successful to ${this.internalName}.`;\n },\n }),\n };\n }\n\n get transfer_tools() {\n return Object.fromEntries(\n this.toHandoffs().flatMap((it) => Object.entries(it.handoffTool)),\n );\n }\n\n get toolsNames() {\n return [\n // Note: do not add the handoff tool itself otherwise it'd create a agent recursion/loop\n ...Object.keys(this.transfer_tools),\n ...Object.keys(this.handoff.tools),\n ];\n }\n\n #prepareInstructions(contextVariables?: C) {\n return [\n typeof this.handoff.instructions === 'function'\n ? this.handoff.instructions(contextVariables)\n : Array.isArray(this.handoff.instructions)\n ? this.handoff.instructions.join('\\n')\n : this.handoff.instructions,\n '',\n '',\n ].join('\\n');\n }\n\n instructions(contextVariables?: C) {\n const text = this.#prepareInstructions(contextVariables);\n const handoffsData = this.toHandoffs();\n\n if (handoffsData.length === 0) {\n return text.replace('<specialized_agents_placeholder>', ' ');\n }\n\n const handoffs = [\n '## Specialized Agents',\n\n '| Agent Name | Agent Description |',\n '| --- | --- |',\n ...handoffsData.map(\n (hf) =>\n `| ${hf.handoff.name} | ${hf.handoff.handoffDescription || 'No description available'} |`,\n ),\n '',\n '',\n ].join('\\n');\n\n return text.replace('<specialized_agents_placeholder>', handoffs);\n }\n\n toHandoffs() {\n const hfs: Agent<unknown, C>[] = [];\n for (const it of this.handoffs ?? []) {\n const hf = typeof it === 'function' ? it() : it;\n hf.parent = this;\n hfs.push(hf);\n }\n return hfs;\n }\n\n asTool(props?: {\n toolDescription?: string;\n outputExtractor?: OutputExtractorFn;\n }) {\n return tool({\n description: props?.toolDescription || this.handoff.handoffDescription,\n inputSchema: z.object({\n input: z.string(),\n }),\n execute: async ({ input }, options) => {\n try {\n const result = await generateText({\n model: this.model!,\n system: this.#prepareInstructions(),\n prompt: input,\n temperature: 0,\n tools: this.handoff.tools,\n abortSignal: options.abortSignal,\n stopWhen: stepCountIs(25),\n experimental_context: options.experimental_context,\n experimental_output: this.output\n ? Output.object({ schema: this.output })\n : undefined,\n onStepFinish: (step) => {\n const toolCall = step.toolCalls.at(-1);\n if (toolCall) {\n console.log(\n `Debug: ${chalk.yellow('ToolCalled')}: ${toolCall.toolName}(${JSON.stringify(toolCall.input)})`,\n );\n }\n },\n prepareStep: prepareStep(\n this,\n this.model!,\n options.experimental_context,\n ),\n });\n if (props?.outputExtractor) {\n return await props.outputExtractor(result);\n }\n return result.steps.map((it) => it.toolResults).flat();\n } catch (error) {\n console.error(error);\n return `Error: ${JSON.stringify(error)}`;\n }\n },\n });\n }\n\n toTool(props?: {\n toolDescription?: string;\n outputExtractor?: OutputExtractorFn;\n }) {\n return { [this.handoffToolName]: this.asTool(props) };\n }\n\n debug(prefix = '') {\n console.log(\n `Debug: ${chalk.bgMagenta('Agent')}: ${chalk.bold(this.handoff.name)}`,\n );\n // console.log(\n // `Debug: ${chalk.blue('Tools')}: ${Object.keys(toToolset(agent))}`,\n // );\n const transferTools = this.toolsNames\n .filter((toolName) => toolName.startsWith('transfer_to'))\n .map((toolName) => toolName.replace('transfer_to_', ''));\n const agentTools = this.toolsNames.filter(\n (toolName) => !toolName.startsWith('transfer_to'),\n );\n console.log(\n `Debug: ${chalk.blue('TransferTools')}: ${transferTools.length ? transferTools : 'None'}`,\n );\n console.log(\n `Debug: ${chalk.blue('Agent Tools')}: ${agentTools.length ? agentTools : 'None'}`,\n );\n // if (!isEmpty(agent.handoff.handoffs)) {\n // console.log(`${prefix}Handoffs:`);\n // for (const handoff of agent.handoff.handoffs) {\n // debugAgent(handoff, `${prefix} `);\n // }\n // }\n }\n\n toToolset(options?: {\n includeTransferTool?: boolean;\n includeHandoffs?: boolean;\n }): Record<string, Tool> {\n const tools = flattenTools(\n this as Agent<unknown, C>,\n (node) => node.toHandoffs(),\n (node) => node.handoff.tools,\n );\n\n return {\n ...Object.fromEntries(tools.flatMap((it) => Object.entries(it))),\n ...(options?.includeTransferTool !== false ? this.transfer_tools : {}),\n ...(options?.includeHandoffs !== false ? this.handoffTool : {}),\n };\n }\n\n clone(\n agent?: Omit<Partial<CreateAgent<Output, C>>, 'handoffs'>,\n ): Agent<Output, C> {\n return new Agent<Output, C>({\n prepareHandoff: (messages) => {\n this.prepareHandoff?.(messages);\n },\n model: agent?.model ?? this.model,\n toolChoice: agent?.toolChoice ?? this.toolChoice,\n prompt: agent?.prompt ?? this.handoff.instructions,\n tools: agent?.tools ?? this.handoff.tools,\n name: agent?.name ?? this.handoff.name,\n handoffDescription:\n agent?.handoffDescription ?? this.handoff.handoffDescription,\n handoffs: [...this.handoffs],\n output: agent?.output ?? this.output,\n });\n }\n}\n\nfunction flattenTools<T, R>(\n root: T,\n getChildren: (node: T) => T[],\n extract: (node: T) => R,\n): R[] {\n const stack: T[] = [root];\n const visited = new Set<T>();\n const result: R[] = [];\n\n while (stack.length) {\n const node = stack.pop()!;\n if (visited.has(node)) continue;\n visited.add(node);\n result.push(extract(node));\n stack.push(...getChildren(node));\n }\n\n return result;\n}\n\nexport type Instruction<C> =\n | string\n | string[]\n | ((contextVariables?: C) => string);\n\nexport interface PurposeRoutineInstructions {\n purpose: string | string[];\n routine: string[];\n}\n\nexport function instructions({ purpose, routine }: PurposeRoutineInstructions) {\n const lines = [\n '# Agent Context',\n ...(Array.isArray(purpose) ? purpose : [purpose]),\n '',\n '',\n '<specialized_agents_placeholder>',\n ];\n\n if (routine.length) {\n lines.push(\n `Use the following routine to fulfill the task.`,\n `# Routine`,\n ...routine.map((it, i) => `${i + 1}. ${it}`),\n );\n }\n\n return lines.join('\\n');\n}\n\ninstructions.swarm = ({ purpose, routine }: PurposeRoutineInstructions) => {\n const lines = [\n RECOMMENDED_PROMPT_PREFIX,\n '',\n '',\n '# Agent Context',\n ...(Array.isArray(purpose) ? purpose : [purpose]),\n '',\n '',\n '<specialized_agents_placeholder>',\n ];\n\n if (routine.length) {\n lines.push(\n `Use the following routine to fulfill the task.`,\n `# Routine`,\n ...routine.map((it, i) => `${i + 1}. ${it}`),\n );\n }\n\n return lines.join('\\n');\n};\n\ninstructions.supervisor = ({\n purpose,\n routine,\n}: PurposeRoutineInstructions) => {\n const lines = [\n SUPERVISOR_PROMPT_PREFIX,\n '',\n '',\n '# Agent Context',\n ...(Array.isArray(purpose) ? purpose : [purpose]),\n '',\n '',\n '<specialized_agents_placeholder>',\n ];\n\n if (routine.length) {\n lines.push(\n `Use the following routine to fulfill the task.`,\n `# Routine`,\n ...routine.filter(Boolean).map((it, i) => `${i + 1}. ${it}`),\n );\n }\n\n return lines.join('\\n');\n};\n\ninstructions.supervisor_subagent = ({\n purpose,\n routine,\n}: PurposeRoutineInstructions) => {\n const lines = [\n SUPERVISOR_PROMPT_PREFIX,\n '',\n '',\n '# Agent Context',\n ...(Array.isArray(purpose) ? purpose : [purpose]),\n '',\n ];\n\n if (routine.length) {\n lines.push(\n `Use the following routine to fulfill the task. Execute ALL steps immediately.`,\n `# Routine`,\n ...routine.map((it, i) => `${i + 1}. ${it}`),\n `${routine.length + 1}. transfer_to_supervisor_agent`,\n // `1. IMMEDIATELY START: ${routine[0]}`,\n // ...routine.slice(1).map((it, i) => `${i + 2}. ${it}`),\n // `${routine.length + 1}. STOP HERE - Do not do any other agent's work`,\n // `${routine.length + 2}. MANDATORY: You MUST call transfer_to_supervisor_agent function RIGHT NOW to return control`,\n // `${routine.length + 3}. DO NOT END YOUR RESPONSE WITHOUT CALLING THE TRANSFER FUNCTION`,\n );\n } else {\n lines.push(\n 'CRITICAL: end the generation by calling transfer_to_supervisor_agent tool',\n );\n }\n\n return lines.join('\\n');\n};\n\ntype TransferResult = { lastActiveAgent: string; currentActiveAgent: string };\nexport type TransferTool = { output: TransferResult };\nexport function isTransferToolResult(\n call: unknown | undefined,\n): call is TransferTool {\n if (!call) {\n return false;\n }\n if (typeof call !== 'object') {\n return false;\n }\n if (!('output' in call)) {\n return false;\n }\n const lastActiveAgent = (call.output as Record<string, string>)\n .lastActiveAgent;\n\n if (!lastActiveAgent) {\n return false;\n }\n return true;\n}\n\nexport function lastTransferResult(messages: ResponseMessage[]) {\n for (let i = messages.length - 1; i >= 0; i--) {\n const message = messages[i];\n for (let i = message.parts.length - 1; i >= 0; i--) {\n const part = message.parts[i];\n if (\n part.type === 'dynamic-tool' &&\n part.toolName.startsWith('transfer_to_') &&\n part.state === 'output-available' &&\n isTransferToolResult(part)\n ) {\n return part.output;\n }\n }\n }\n return undefined;\n}\n", "import dedent from 'dedent';\n\nexport const RECOMMENDED_PROMPT_PREFIX = [\n `# System context`,\n `You are part of a multi-agent system called the DeepAgents SDK, designed to make agent coordination and execution easy.`,\n `Agents uses two primary abstraction: **Agents** and **Handoffs**.`,\n `An agent encompasses instructions and tools and can hand off a conversation to another agent when appropriate.`,\n `Handoffs are achieved by calling a handoff function, generally named \\`transfer_to_<agent_name>\\`.`,\n `Transfers between agents are handled seamlessly in the background; do not mention or draw attention to these transfers in your conversation with the user.`,\n // 'Do not pass context between agents. the agents already have the complete context without agent to agent communication.',\n\n // From 4.1 beast mode\n // `Please keep going until the user\u2019s query is completely resolved, before ending your turn and yielding back to the user.`,\n // `Your thinking should be thorough and so it's fine if it's very long. However, avoid unnecessary repetition and verbosity. You should be concise, but thorough.`,\n // `You MUST iterate and keep going until the problem is solved.`,\n // `You have everything you need to resolve this problem. I want you to fully solve this autonomously before coming back to me.`,\n // `Only terminate your turn when you are sure that the problem is solved and all items have been checked off. Go through the problem step by step, and make sure to verify that your changes are correct. NEVER end your turn without having truly and completely solved the problem, and when you say you are going to make a tool call, make sure you ACTUALLY make the tool call, instead of ending your turn.`,\n // `Always tell the user what you are going to do before making a tool call with a single concise sentence. This will help them understand what you are doing and why.`,\n // `If the user request is \"resume\" or \"continue\" or \"try again\", check the previous conversation history to see what the next incomplete step in the todo list is. Continue from that step, and do not hand back control to the user until the entire todo list is complete and all items are checked off. Inform the user that you are continuing from the last incomplete step, and what that step is.`,\n // `Take your time and think through every step - remember to check your solution rigorously and watch out for boundary cases, especially with the changes you made. Use the sequential thinking tool if available. Your solution must be perfect. If not, continue working on it. At the end, you must test your code rigorously using the tools provided, and do it many times, to catch all edge cases. If it is not robust, iterate more and make it perfect. Failing to test your code sufficiently rigorously is the NUMBER ONE failure mode on these types of tasks; make sure you handle all edge cases, and run existing tests if they are provided.`,\n // `You MUST plan extensively before each function call, and reflect extensively on the outcomes of the previous function calls. DO NOT do this entire process by making function calls only, as this can impair your ability to solve the problem and think insightfully.`,\n // `You MUST keep working until the problem is completely solved, and all items in the todo list are checked off. Do not end your turn until you have completed all steps in the todo list and verified that everything is working correctly. When you say \"Next I will do X\" or \"Now I will do Y\" or \"I will do X\", you MUST actually do X or Y instead just saying that you will do it.`,\n // `You are a highly capable and autonomous agent, and you can definitely solve this problem without needing to ask the user for further input.`,\n].join('\\n');\n\nexport const SUPERVISOR_PROMPT_PREFIX = dedent`\n# System Context\nYou are part of a multi-agent system called the DeepAgents SDK, designed to facilitate agent coordination and execution.\n\n- The primary agent, known as the \"Supervisor Agent,\" coordinates communication between specialized agents. The Supervisor Agent does not perform specialized tasks but acts as the central point for communication.\n- Specialized agents must transfer control back to the Supervisor Agent upon completing their tasks.\n\n**Core Directives:**\n- Begin with a concise checklist (3-7 bullets) of what you will do for each user query; items should be conceptual, not implementation-level.\n- Continue working until the user's query is completely resolved; only then yield control back to the user.\n- Your thinking must be thorough and step-by-step. Aim for completeness and rigor while avoiding unnecessary repetition and verbosity.\n- You must iterate and keep working until the problem is fully solved. You have all the requirements and information needed; solve the problem autonomously without user intervention.\n- Do not terminate your turn unless you are certain all issues are resolved and the entire todo list is complete and verified.\n- When making tool calls, explicitly state, in a single concise sentence, the purpose and minimal inputs for the action before executing it.\n- After each tool call or code edit, validate the result in 1-2 lines and proceed or self-correct if validation fails.\n- For requests such as \"resume\", \"continue\", or \"try again\":\n - Check previous conversation history to determine the next incomplete todo step, continue from there, and do not return control until all items are complete.\n - Inform the user you are resuming from the last incomplete step, and specify what that step is.\n- Take your time and rigorously check your solution, especially edge and boundary cases. Use sequential thinking tools when available. Your solution must be robust and perfect; continue iterating and retesting as needed.\n- Always test your code using all available tools and provided tests, with repetition as necessary to catch edge cases.\n- Plan extensively before each function/tool call and reflect thoroughly on previous actions before proceeding. Do not proceed solely by chaining function calls\u2014use stepwise planning and reflection.\n- Explicitly complete every todo list item and confirm all steps are working before ending your turn. Always follow through on stated actions.\n- You are a highly capable, autonomous agent, and should not require additional user input to fully solve the task.\n`;\n", "import {\n type GenerateTextResult,\n type InferUIMessageChunk,\n type StreamTextResult,\n type Tool,\n type ToolCallOptions,\n type UIDataTypes,\n type UIMessage,\n type UITools,\n generateId,\n} from 'ai';\nimport { flow } from 'lodash-es';\nimport { createWriteStream } from 'node:fs';\nimport { createInterface } from 'node:readline/promises';\nimport { Readable } from 'node:stream';\nimport { isPromise } from 'node:util/types';\n\nimport {\n visualizeMermaid,\n visualizeRichSemantic,\n visualizeSemantic,\n} from './visualize.ts';\n\nexport async function streamWrite(\n response: StreamTextResult<Record<string, Tool>, never>,\n) {\n response.consumeStream();\n const writeStream = createWriteStream('blog_writer_output.md');\n Readable.fromWeb(response.textStream as any).pipe(writeStream);\n\n // for await (const chunk of response.toUIMessageStream()) {\n // if (chunk.type === 'reasoning-start') {\n // writeStream.write('\\n# reasoning\\n');\n // }\n // if (chunk.type === 'reasoning-delta') {\n // writeStream.write(chunk.delta);\n // }\n // if (chunk.type === 'reasoning-end') {\n // writeStream.write('\\n# /reasoning\\n');\n // }\n // if (chunk.type === 'text-start') {\n // writeStream.write('\\n# text\\n');\n // }\n // if (chunk.type === 'text-delta') {\n // writeStream.write(chunk.delta);\n // }\n // if (chunk.type === 'text-end') {\n // writeStream.write('\\n# /text\\n');\n // }\n // }\n console.log(await response.totalUsage);\n}\n\nfunction printChunk(\n chunk: InferUIMessageChunk<UIMessage<unknown, UIDataTypes, UITools>>,\n options: { reasoning: boolean; wrapInTags: boolean; text: boolean },\n) {\n const {\n reasoning: includeReasoning,\n wrapInTags,\n text: includeText,\n } = options;\n if (includeReasoning) {\n if (chunk.type === 'reasoning-start') {\n process.stdout.write(`\\n${wrapInTags ? '<reasoning>' : ''}\\n`);\n }\n if (chunk.type === 'reasoning-delta') {\n process.stdout.write(chunk.delta);\n }\n if (chunk.type === 'reasoning-end') {\n process.stdout.write(`\\n${wrapInTags ? '</reasoning>' : ''}\\n`);\n }\n }\n if (includeText) {\n if (chunk.type === 'text-start') {\n process.stdout.write(`\\n${wrapInTags ? '<text>' : ''}\\n`);\n }\n if (chunk.type === 'text-delta') {\n process.stdout.write(chunk.delta);\n }\n if (chunk.type === 'text-end') {\n process.stdout.write(`\\n${wrapInTags ? '</text>' : ''}\\n`);\n }\n }\n}\n\nexport const printer = {\n readableStream: async (\n stream: ReadableStream<\n InferUIMessageChunk<UIMessage<unknown, UIDataTypes, UITools>>\n >,\n options?: { reasoning?: boolean; wrapInTags?: boolean; text?: boolean },\n ) => {\n const includeReasoning = options?.reasoning ?? true;\n const wrapInTags = options?.wrapInTags ?? true;\n const includeText = options?.text ?? true;\n for await (const chunk of stream as any) {\n printChunk(chunk, {\n reasoning: includeReasoning,\n wrapInTags,\n text: includeText,\n });\n }\n },\n stdout: async (\n response: StreamTextResult<Record<string, Tool>, unknown>,\n options?: { reasoning?: boolean; text?: boolean; wrapInTags?: boolean },\n ) => {\n const includeReasoning = options?.reasoning ?? true;\n const includeText = options?.text ?? true;\n const wrapInTags = options?.wrapInTags ?? true;\n for await (const chunk of response.toUIMessageStream()) {\n printChunk(chunk, {\n reasoning: includeReasoning,\n text: includeText,\n wrapInTags,\n });\n }\n console.log(await response.totalUsage);\n },\n mermaid: flow(visualizeMermaid, console.log),\n semantic: flow(visualizeSemantic, console.log),\n richSemantic: flow(visualizeRichSemantic, console.log),\n};\n\nexport function messageToUiMessage(message: string): UIMessage {\n return {\n id: generateId(),\n role: 'user',\n parts: [\n {\n type: 'text',\n text: message,\n },\n ],\n };\n}\nexport const user = messageToUiMessage;\n\nexport async function input(defaultValue?: string): Promise<string> {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n const answer = await rl.question(\n `Please enter your input${defaultValue ? ` (default: ${defaultValue})` : ''}: `,\n );\n rl.close();\n return answer || defaultValue || '';\n}\n\nexport async function confirm(\n message: string,\n defaultValue = true,\n): Promise<boolean> {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n const defaultText = defaultValue ? 'Y/n' : 'y/N';\n\n while (true) {\n const answer = await rl.question(`${message} (${defaultText}): `);\n const normalized = answer.toLowerCase().trim();\n\n // If empty answer, use default\n if (normalized === '') {\n rl.close();\n return defaultValue;\n }\n\n if (normalized === 'y' || normalized === 'yes') {\n rl.close();\n return true;\n } else if (normalized === 'n' || normalized === 'no') {\n rl.close();\n return false;\n } else {\n console.log(\n 'Please answer with y/yes or n/no (or press Enter for default)',\n );\n }\n }\n}\n\nexport async function last<T>(iterable: AsyncIterable<T>, position = -1) {\n const arr = await Array.fromAsync(iterable);\n return arr.at(position)!;\n}\nexport async function finished<T>(iterable: AsyncIterable<T>) {\n await Array.fromAsync(iterable);\n}\n\nexport function toOutput<T>(\n result:\n | Promise<GenerateTextResult<Record<string, Tool>, T>>\n | StreamTextResult<Record<string, Tool>, T>,\n) {\n return isPromise(result)\n ? result.then((res) => res.experimental_output)\n : last(result.experimental_partialOutputStream);\n}\n\nexport function toState<C>(options: ToolCallOptions) {\n return options.experimental_context as C;\n}\n", "import { titlecase } from 'stringcase';\n\nimport type { Agent } from './agent.ts';\n\nexport type VisualizeOptions = {\n direction?: 'LR' | 'TB' | 'BT' | 'RL';\n showTools?: boolean;\n};\n\ntype Node = {\n id: string;\n name: string;\n tools: string[];\n};\n\ntype Edge = {\n from: string; // node id\n to: string; // node id\n label: string; // e.g., transfer_to_X\n};\n\n/**\n * Build a minimal Mermaid flowchart to visualize agents, their local tools, and handoff transfers.\n *\n * - Agent nodes include their name and (optionally) their tool names.\n * - Edges represent transfer tools (handoffs) from one agent to another, labeled by the transfer tool name.\n */\nexport function visualizeMermaid(\n root: Agent<any>,\n options: VisualizeOptions = {},\n): string {\n const { direction = 'LR', showTools = true } = options;\n\n const nodes: Node[] = [];\n const edges: Edge[] = [];\n\n const seen = new Set<string>();\n const nameToId = new Map<string, string>();\n\n const sanitizeId = (name: string) =>\n name\n .toLowerCase()\n .replace(/[^a-z0-9]+/gi, '_')\n .replace(/^_+|_+$/g, '');\n\n const ensureNode = (agent: Agent) => {\n const name = agent.handoff.name;\n if (!nameToId.has(name)) {\n // Guarantee unique ids even if sanitize collides\n const base = sanitizeId(name) || 'agent';\n let id = base;\n let i = 1;\n while (nodes.some((n) => n.id === id)) id = `${base}_${i++}`;\n nameToId.set(name, id);\n\n nodes.push({\n id,\n name,\n tools: Object.keys(agent.handoff.tools ?? {}),\n });\n }\n return nameToId.get(name)!;\n };\n\n const stack: Agent[] = [root];\n while (stack.length) {\n const current = stack.pop()!;\n const currentName = current.handoff.name;\n if (seen.has(currentName)) continue;\n seen.add(currentName);\n\n const fromId = ensureNode(current);\n\n for (const child of current.toHandoffs()) {\n const toId = ensureNode(child);\n // Prefer the child's declared handoff tool key (usually transfer_to_{childName})\n const label = Object.keys(child.handoffTool)[0].replace(\n /transfer_to_/g,\n '',\n );\n edges.push({ from: fromId, to: toId, label });\n stack.push(child);\n }\n }\n\n const lines: string[] = [];\n lines.push(`flowchart ${direction}`);\n\n // Nodes\n for (const n of nodes) {\n const name = titlecase(n.name.replace(/_agent/g, '').replace(/_/g, ' '));\n const toolLine =\n showTools && n.tools.length\n ? `<br/>tools: ${n.tools.map((it) => it.replace(/transfer_to_/g, '')).join(', ')}`\n : '';\n // Use double quotes for label to allow <br/>\n lines.push(`${n.id}[\"${escapeLabel(`Agent: ${name}${toolLine}`)}\"]`);\n }\n\n // Edges\n for (const e of edges) {\n lines.push(`${e.from} -- ${escapeLabel(e.label)} --> ${e.to}`);\n }\n\n return lines.join('\\n');\n}\n\nfunction escapeLabel(s: string): string {\n // Minimal escaping for quotes in Mermaid node labels\n return s.replace(/\"/g, '\\\\\"');\n}\n\n/**\n * Convenience alias with simpler name.\n */\nexport const visualize = visualizeMermaid;\n\n/**\n * Produce a semantic, human-readable map of transfers between agents.\n * Example lines:\n * supervisor transfers to: agentx, agenty\n * agentx transfers to: supervisor\n */\nexport function visualizeSemantic(root: Agent): string {\n const lines: string[] = [];\n const seen = new Set<string>();\n const stack: Agent[] = [root];\n\n while (stack.length) {\n const current = stack.pop()!;\n const currentName = current.handoff.name;\n if (seen.has(currentName)) continue;\n seen.add(currentName);\n\n const from = current.handoff.name;\n const transfers = current.toHandoffs().map((h) => h.handoff.name);\n const uniqueTransfers = Array.from(new Set(transfers));\n const rhs = uniqueTransfers.length ? uniqueTransfers.join(', ') : 'none';\n lines.push(`${from} transfers to: ${rhs}`);\n\n for (const child of current.toHandoffs()) stack.push(child);\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Minimal arrow-based semantic visualizer.\n * Prints one line per transfer using Unicode arrows, e.g.:\n * supervisor \u2500\u2500\u25B6 agentx\n * supervisor \u2500\u2500\u25B6 agenty\n * agentx \u2500\u2500\u25B6 supervisor\n */\nexport function visualizeRichSemantic(root: Agent): string {\n const stack: Agent[] = [root];\n const seen = new Set<string>();\n const edgeSet = new Set<string>();\n const edges: Array<{ from: string; to: string }> = [];\n\n while (stack.length) {\n const current = stack.pop()!;\n const from = current.handoff.name;\n if (!seen.has(from)) {\n seen.add(from);\n for (const child of current.toHandoffs()) {\n const to = child.handoff.name;\n const key = `${from}->${to}`;\n if (!edgeSet.has(key)) {\n edgeSet.add(key);\n edges.push({ from, to });\n }\n stack.push(child);\n }\n }\n }\n\n if (edges.length === 0) return `${root.handoff.name} \u2500\u2500\u25B6 none`;\n return edges.map(({ from, to }) => `${from} \u2500\u2500\u25B6 ${to}`).join('\\n');\n}\n", "import { groq } from '@ai-sdk/groq';\nimport {\n type CoreMessage,\n type ModelMessage,\n NoSuchToolError,\n Output,\n type PrepareStepFunction,\n type PrepareStepResult,\n type StepResult,\n type Tool,\n type UIDataTypes,\n type UIMessage,\n type UIMessagePart,\n type UITools,\n convertToModelMessages,\n createUIMessageStream,\n generateId,\n generateText,\n smoothStream,\n stepCountIs,\n streamText,\n wrapLanguageModel,\n} from 'ai';\nimport chalk from 'chalk';\nimport dedent from 'dedent';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\n\nimport {\n type Agent,\n type AgentModel,\n type TransferTool,\n isTransferToolResult,\n} from './agent.ts';\nimport { last, messageToUiMessage, user } from './stream_utils.ts';\n\nexport type OutputMode = 'full_history' | 'last_message';\n\nexport interface ExecuteOptions {\n contextVariables?: Record<string, unknown>;\n systemPrompt?: string;\n abortSignal?: AbortSignal;\n outputMode?: OutputMode;\n}\n\nfunction isToolMessage(message: CoreMessage): boolean {\n return message.role === 'tool';\n}\n\nfunction filterAgentOutput(\n allMessages: CoreMessage[],\n startIndex: number,\n outputMode: OutputMode,\n): CoreMessage[] {\n if (outputMode === 'full_history') {\n return allMessages; // Include all messages generated by agent\n }\n\n if (outputMode === 'last_message') {\n const agentMessages = allMessages.slice(startIndex);\n if (agentMessages.length === 0) return allMessages;\n\n const lastMsg = agentMessages[agentMessages.length - 1];\n\n // LangChain logic: if isinstance(messages[-1], ToolMessage): messages = messages[-2:]\n // If last message is a tool message, keep AI message + tool message pair\n if (isToolMessage(lastMsg) && agentMessages.length > 1) {\n const beforeLastMsg = agentMessages[agentMessages.length - 2];\n if (beforeLastMsg.role === 'assistant') {\n return [...allMessages.slice(0, startIndex), beforeLastMsg, lastMsg];\n }\n }\n\n // LangChain logic: else: messages = messages[-1:]\n // Otherwise, keep just the last message\n return [...allMessages.slice(0, startIndex), lastMsg];\n }\n\n return allMessages;\n}\n\nexport function run<O, C>(\n agent: Agent<O, C>,\n messages: UIMessage[] | string,\n contextVariables: C,\n config?: {\n abortSignal?: AbortSignal;\n providerOptions?: Parameters<typeof streamText>[0]['providerOptions'];\n },\n) {\n return generateText({\n abortSignal: config?.abortSignal,\n providerOptions: config?.providerOptions,\n model: agent.model,\n system: agent.instructions(contextVariables),\n messages: convertToModelMessages(\n Array.isArray(messages) ? messages : [user(messages)],\n ),\n temperature: agent.temperature,\n stopWhen: stepCountIs(25),\n tools: agent.toToolset(),\n activeTools: agent.toolsNames,\n experimental_context: contextVariables,\n toolChoice: agent.toolChoice,\n experimental_output: agent.output\n ? Output.object({ schema: agent.output })\n : undefined,\n // onStepFinish: (step) => tagAgents(step, agent.handoff.name),\n onStepFinish: (step) => {\n const toolCall = step.toolCalls.at(-1);\n if (toolCall) {\n console.log(\n `Debug: ${chalk.yellow('ToolCalled')}: ${toolCall.toolName}(${JSON.stringify(toolCall.input)})`,\n );\n }\n },\n prepareStep: prepareStep(agent, agent.model, contextVariables),\n // onFinish: (result) => {\n // (contextVariables as any).content = result.content;\n // },\n });\n}\n\nexport function execute<O, C>(\n agent: Agent<O, C>,\n messages: UIMessage[] | string,\n contextVariables: C,\n config?: {\n abortSignal?: AbortSignal;\n providerOptions?: Parameters<typeof streamText>[0]['providerOptions'];\n },\n) {\n return streamText({\n abortSignal: config?.abortSignal,\n providerOptions: config?.providerOptions,\n model: agent.model,\n system: agent.instructions(contextVariables),\n messages: convertToModelMessages(\n Array.isArray(messages) ? messages : [user(messages)],\n ),\n temperature: agent.temperature,\n stopWhen: stepCountIs(25),\n experimental_transform: smoothStream(),\n tools: agent.toToolset(),\n activeTools: agent.toolsNames,\n experimental_context: contextVariables,\n toolChoice: agent.toolChoice,\n experimental_repairToolCall: async ({\n toolCall,\n tools,\n inputSchema,\n error,\n }) => {\n if (NoSuchToolError.isInstance(error)) {\n return null; // do not attempt to fix invalid tool names\n }\n\n const tool = tools[toolCall.toolName as keyof typeof tools];\n\n const { experimental_output } = await generateText({\n model: groq('openai/gpt-oss-20b'),\n experimental_output: Output.object({ schema: tool.inputSchema }),\n prompt: [\n `The model tried to call the tool \"${toolCall.toolName}\"` +\n ` with the following inputs:`,\n JSON.stringify(toolCall.input),\n `The tool accepts the following schema:`,\n JSON.stringify(inputSchema(toolCall)),\n 'Please fix the inputs.',\n ].join('\\n'),\n });\n\n return { ...toolCall, input: JSON.stringify(experimental_output) };\n },\n onError: (error) => {\n console.error(\n chalk.red(`Error during agent (${agent.internalName}) execution: `),\n error instanceof Error ? error.message : error,\n );\n console.dir(error, { depth: null });\n },\n experimental_output: agent.output\n ? Output.object({ schema: agent.output })\n : undefined,\n // onStepFinish: (step) => tagAgents(step, agent.handoff.name),\n onStepFinish: (step) => {\n const toolCall = step.toolCalls.at(-1);\n if (toolCall) {\n console.log(\n `Debug: ${chalk.yellow('ToolCalled')}: ${toolCall.toolName}(${JSON.stringify(toolCall.input)})`,\n );\n }\n },\n prepareStep: prepareStep(agent, agent.model, contextVariables),\n // onFinish: (result) => {\n // (contextVariables as any).content = result.content;\n // },\n });\n}\n\nexport const stream = execute;\nexport const generate = run;\n\nexport const prepareStep = <C>(\n agent: Agent<unknown, C>,\n model: AgentModel,\n contextVariables: C,\n): PrepareStepFunction<NoInfer<Record<string, Tool>>> => {\n return async ({ steps, messages }) => {\n const step = steps.at(-1);\n const agentName = (contextVariables as any).currentActiveAgent;\n if (!step) {\n return await prepareAgent(model, agent, messages, contextVariables);\n }\n if (!agentName) {\n return await prepareAgent(model, agent, messages, contextVariables);\n }\n\n const nextAgent = findAgent(agent, agentName);\n if (!nextAgent) {\n console.error(`Debug: ${chalk.red('NotFound')}: Agent ${agentName}`);\n console.dir(\n {\n steps: steps.map(({ request, response, ...etc }) => etc),\n messages,\n },\n { depth: null },\n );\n return void 0;\n }\n return await prepareAgent(model, nextAgent, messages, contextVariables);\n };\n};\n\nexport function swarm<C>(\n agent: Agent<unknown, C>,\n messages: UIMessage[] | string,\n contextVariables: C,\n abortSignal?: AbortSignal,\n) {\n const originalMessages = Array.isArray(messages)\n ? messages\n : [messageToUiMessage(messages)];\n return createUIMessageStream({\n originalMessages,\n generateId: generateId,\n async execute({ writer }) {\n const stream = execute(agent, originalMessages, contextVariables, {\n abortSignal,\n });\n const parts: UIMessagePart<UIDataTypes, UITools>[] = [];\n\n writer.merge(\n stream.toUIMessageStream({\n sendFinish: false,\n sendStart: true,\n onFinish: (event) => {\n parts.push(...event.responseMessage.parts);\n },\n }),\n );\n await stream.consumeStream({ onError: console.error });\n await last(stream.fullStream);\n\n if (!agent.prepareEnd) return;\n\n while (true) {\n const state = contextVariables as any;\n if (state.currentActiveAgent === undefined) {\n console.warn(\n `swarm: active agent was never set, so no prepareEnd call will be made`,\n );\n return;\n }\n if (state.currentActiveAgent === agent.internalName) {\n console.warn(\n `swarm: active agent is the root agent, so no prepareEnd call will be made`,\n );\n return;\n }\n const responseMessage = { id: '', parts, role: 'assistant' } as const;\n\n const stream = agent.prepareEnd({\n responseMessage,\n messages: [...originalMessages, responseMessage],\n contextVariables,\n abortSignal,\n });\n if (!stream) break;\n\n writer.merge(\n stream.toUIMessageStream({\n sendFinish: false,\n sendStart: false,\n onFinish: (event) => {\n parts.push(...event.responseMessage.parts);\n },\n }),\n );\n await stream.consumeStream({ onError: console.error });\n await last(stream.fullStream);\n }\n\n writer.write({ type: 'finish' });\n },\n });\n}\n\nexport async function prepareAgent<C>(\n defaultModel: AgentModel,\n agent: Agent<unknown, C>,\n messages: ModelMessage[],\n contextVariables?: C,\n): Promise<PrepareStepResult<NoInfer<Record<string, Tool>>>> {\n agent.debug();\n await agent.prepareHandoff?.(messages);\n\n let stepModel = agent.model ?? defaultModel;\n if (agent.output) {\n const json_schema = zodToJsonSchema(agent.output, {\n $refStrategy: 'root',\n });\n stepModel = wrapLanguageModel({\n model: stepModel,\n middleware: {\n transformParams: async ({ params }) => ({\n ...params,\n response_format: {\n type: 'json_schema',\n json_schema,\n name: `${agent.handoff.name}_output`,\n },\n }),\n },\n });\n }\n return {\n system: agent.instructions(contextVariables),\n activeTools: agent.toolsNames,\n model: stepModel,\n messages,\n // messages: removeTransferCalls(messages),\n toolChoice: agent.toolChoice,\n } as const;\n}\n\nfunction getLastAgentFromSteps(\n steps: StepResult<NoInfer<Record<string, Tool>>>[],\n): string | undefined {\n for (let i = steps.length - 1; i >= 0; i--) {\n const step = steps[i];\n for (const it of step.dynamicToolResults) {\n if (isTransferToolResult(it)) {\n return it.output.currentActiveAgent;\n }\n }\n }\n return void 0;\n}\n\nfunction findAgent<C>(agent: Agent<unknown, C>, agentName: string) {\n // FIXME: first argument agent not always the first passed agent.\n return [...agent.toHandoffs(), agent].find(\n (it) => it.handoff.name === agentName,\n );\n}\n\nfunction getActiveAgentName(messages: ModelMessage[]): string | undefined {\n for (let i = messages.length - 1; i >= 0; i--) {\n const message = messages[i];\n\n if (message.role === 'tool') {\n for (const block of message.content) {\n if (\n block.type === 'tool-result' &&\n block.toolName.startsWith('transfer_to_') &&\n block.output.type === 'json' &&\n isTransferToolResult({ output: block.output.value })\n ) {\n return (block.output.value as TransferTool['output'])\n .currentActiveAgent;\n }\n }\n }\n }\n return undefined;\n}\n\nfunction tagAgents(\n step: StepResult<NoInfer<Record<string, Tool>>>,\n defaultAgentName: string,\n) {\n const { request, response, ...stepResult } = step;\n // let transferToolResultIdx = -1;\n const messages = response.messages;\n let agentName: string | undefined;\n\n // look for the last agent from the step\n for (let i = stepResult.content.length - 1; i >= 0; i--) {\n const block = stepResult.content[i];\n if (\n block.type === 'tool-result' &&\n block.dynamic &&\n block.toolName.startsWith('transfer_to_') &&\n isTransferToolResult(block)\n ) {\n // If we found a dynamic tool result, we can use it\n agentName = block.output.lastActiveAgent;\n // transferToolResultIdx = i;\n break;\n }\n }\n\n // if no agent in the step result, look for for it in the messages\n // todo: can we just use this instead of looking into the step result?\n if (!agentName) {\n for (const message of messages.slice(0).reverse()) {\n if (\n message.role === 'tool' &&\n message.content[0].type === 'tool-result' &&\n message.content[0].toolName.startsWith('transfer_to_') &&\n isTransferToolResult({\n output: message.content[0].output.value,\n })\n ) {\n agentName = (message.content[0].output.value as TransferTool['output'])\n .currentActiveAgent;\n break;\n }\n }\n }\n\n if (!agentName) {\n agentName = defaultAgentName;\n }\n\n for (const block of stepResult.content) {\n if (block.type === 'text' && !block.text.startsWith('<name>')) {\n block.text = `<name>${agentName}</name><content>${dedent(block.text)}</content>`;\n }\n }\n // console.log(\n // `Debug: ${chalk.red('NoOp')}: No transfer tool result found.`,\n // );\n // console.dir({ stepResult, messages }, { depth: null });\n}\n\nfunction removeTransferCalls(messages: ModelMessage[]): ModelMessage[] {\n for (const message of messages) {\n if (message.role === 'assistant') {\n if (typeof message.content === 'string') continue;\n\n for (let i = message.content.length - 1; i >= 0; i--) {\n const block = message.content[i];\n if (typeof block === 'string') continue;\n\n if (\n (block.type === 'tool-call' || block.type === 'tool-result') &&\n block.toolName.startsWith('transfer_to_')\n ) {\n message.content.splice(i, 1);\n }\n }\n }\n }\n return messages;\n}\n", "import { createOpenAICompatible } from '@ai-sdk/openai-compatible';\nimport { embedMany } from 'ai';\n\nexport const lmstudio = createOpenAICompatible({\n name: 'lmstudio',\n baseURL: 'http://127.0.0.1:1234/v1',\n supportsStructuredOutputs: true,\n includeUsage: true,\n});\n\nexport const glm = createOpenAICompatible({\n name: 'z.ai',\n baseURL: 'https://api.z.ai/api/paas/v4/',\n apiKey: process.env.ZAI_API_KEY,\n});\n\nexport async function embed(documents: string[]): Promise<{\n embeddings: number[][];\n dimensions: number;\n}> {\n const dimensions = 1024;\n const { embeddings } = await embedMany({\n model: lmstudio.textEmbeddingModel('text-embedding-qwen3-embedding-0.6b'),\n values: documents,\n providerOptions: { lmstudio: { dimensions } },\n });\n return { embeddings, dimensions };\n}\n"],
|
|
5
|
+
"mappings": ";AAAA;AAAA,EAIE,UAAAA;AAAA,EAOA;AAAA,EACA,gBAAAC;AAAA,EACA;AAAA,EACA,eAAAC;AAAA,EACA;AAAA,OACK;AACP,OAAOC,YAAW;AAClB,SAAS,iBAAiB;AAC1B,OAAO,OAAO;;;ACnBd,OAAO,YAAY;AAEZ,IAAM,4BAA4B;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeF,EAAE,KAAK,IAAI;AAEJ,IAAM,2BAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACzBxC;AAAA,EASE;AAAA,OACK;AACP,SAAS,YAAY;AACrB,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;;;ACf1B,SAAS,iBAAiB;AA2BnB,SAAS,iBACd,MACA,UAA4B,CAAC,GACrB;AACR,QAAM,EAAE,YAAY,MAAM,YAAY,KAAK,IAAI;AAE/C,QAAM,QAAgB,CAAC;AACvB,QAAM,QAAgB,CAAC;AAEvB,QAAM,OAAO,oBAAI,IAAY;AAC7B,QAAM,WAAW,oBAAI,IAAoB;AAEzC,QAAM,aAAa,CAAC,SAClB,KACG,YAAY,EACZ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,KAAK;AAAA,MACd;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;;;AKteA,SAAS,8BAA8B;AACvC,SAAS,iBAAiB;AAEnB,IAAM,WAAW,uBAAuB;AAAA,EAC7C,MAAM;AAAA,EACN,SAAS;AAAA,EACT,2BAA2B;AAAA,EAC3B,cAAc;AAChB,CAAC;AAEM,IAAM,MAAM,uBAAuB;AAAA,EACxC,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ,QAAQ,IAAI;AACtB,CAAC;AAED,eAAsB,MAAM,WAGzB;AACD,QAAM,aAAa;AACnB,QAAM,EAAE,WAAW,IAAI,MAAM,UAAU;AAAA,IACrC,OAAO,SAAS,mBAAmB,qCAAqC;AAAA,IACxE,QAAQ;AAAA,IACR,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAE;AAAA,EAC9C,CAAC;AACD,SAAO,EAAE,YAAY,WAAW;AAClC;",
|
|
6
|
+
"names": ["Output", "generateText", "stepCountIs", "chalk", "agent", "stream", "generateId", "dedent", "agent", "tool", "generateId", "stream", "agent", "input", "generateText", "stepCountIs", "Output", "chalk", "agent", "i"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type GenerateTextResult, type LanguageModel, type ModelMessage, type StreamTextResult, type Tool, type ToolChoice, type UIDataTypes, type UIMessage, type UITools } from 'ai';
|
|
2
|
+
import z from 'zod';
|
|
3
|
+
export interface Handoff<C> {
|
|
4
|
+
name: string;
|
|
5
|
+
instructions: Instruction<C>;
|
|
6
|
+
handoffDescription?: string;
|
|
7
|
+
tools: Record<string, Tool>;
|
|
8
|
+
}
|
|
9
|
+
export type Handoffs<C> = (Agent<unknown, C> | (() => Agent<unknown, C>))[];
|
|
10
|
+
export type Runner<T, C> = (prompt: string, agent: Agent<C>, messages: ModelMessage[]) => Promise<T>;
|
|
11
|
+
type transfer_tool = `transfer_to_${string}`;
|
|
12
|
+
export type ContextVariables = Record<string, unknown>;
|
|
13
|
+
export declare function agent<Output, C = ContextVariables>(config: CreateAgent<Output, C>): Agent<Output, C>;
|
|
14
|
+
export type ResponseMessage = UIMessage<unknown, UIDataTypes, UITools>;
|
|
15
|
+
export type AgentModel = Exclude<LanguageModel, string>;
|
|
16
|
+
export type OutputExtractorFn = (output: GenerateTextResult<Record<string, Tool>, any>) => string | Promise<string>;
|
|
17
|
+
export type PrepareHandoffFn = (messages: ModelMessage[]) => void | Promise<void>;
|
|
18
|
+
export type PrepareEndFn<C> = (config: {
|
|
19
|
+
messages: ResponseMessage[];
|
|
20
|
+
responseMessage: ResponseMessage;
|
|
21
|
+
contextVariables: C;
|
|
22
|
+
abortSignal?: AbortSignal;
|
|
23
|
+
}) => StreamTextResult<Record<string, Tool>, any> | undefined | void;
|
|
24
|
+
export interface CreateAgent<Output, C> {
|
|
25
|
+
name: string;
|
|
26
|
+
prompt: Instruction<C>;
|
|
27
|
+
temperature?: number;
|
|
28
|
+
handoffDescription?: string;
|
|
29
|
+
prepareHandoff?: PrepareHandoffFn;
|
|
30
|
+
prepareEnd?: PrepareEndFn<C>;
|
|
31
|
+
handoffs?: Handoffs<C>;
|
|
32
|
+
tools?: Record<string, Tool>;
|
|
33
|
+
model: AgentModel;
|
|
34
|
+
toolChoice?: ToolChoice<Record<string, unknown>>;
|
|
35
|
+
output?: z.Schema<Output>;
|
|
36
|
+
}
|
|
37
|
+
export declare class Agent<Output = unknown, C = ContextVariables> {
|
|
38
|
+
#private;
|
|
39
|
+
model: AgentModel;
|
|
40
|
+
toolChoice: ToolChoice<Record<string, unknown>> | undefined;
|
|
41
|
+
parent?: Agent<unknown, C>;
|
|
42
|
+
handoffs: Handoffs<C>;
|
|
43
|
+
readonly prepareHandoff?: PrepareHandoffFn;
|
|
44
|
+
readonly prepareEnd?: PrepareEndFn<C>;
|
|
45
|
+
readonly internalName: string;
|
|
46
|
+
readonly handoff: Handoff<C>;
|
|
47
|
+
readonly handoffToolName: transfer_tool;
|
|
48
|
+
readonly handoffTool: Record<string, Tool>;
|
|
49
|
+
readonly output?: z.Schema<Output>;
|
|
50
|
+
readonly temperature?: number;
|
|
51
|
+
constructor(config: CreateAgent<Output, C>);
|
|
52
|
+
get transfer_tools(): {
|
|
53
|
+
[k: string]: Tool;
|
|
54
|
+
};
|
|
55
|
+
get toolsNames(): string[];
|
|
56
|
+
instructions(contextVariables?: C): string;
|
|
57
|
+
toHandoffs(): Agent<unknown, C>[];
|
|
58
|
+
asTool(props?: {
|
|
59
|
+
toolDescription?: string;
|
|
60
|
+
outputExtractor?: OutputExtractorFn;
|
|
61
|
+
}): Tool<{
|
|
62
|
+
input: string;
|
|
63
|
+
}, string | import("ai").TypedToolResult<Record<string, Tool>>[]>;
|
|
64
|
+
toTool(props?: {
|
|
65
|
+
toolDescription?: string;
|
|
66
|
+
outputExtractor?: OutputExtractorFn;
|
|
67
|
+
}): {
|
|
68
|
+
[x: string]: Tool<{
|
|
69
|
+
input: string;
|
|
70
|
+
}, string | import("ai").TypedToolResult<Record<string, Tool>>[]>;
|
|
71
|
+
};
|
|
72
|
+
debug(prefix?: string): void;
|
|
73
|
+
toToolset(options?: {
|
|
74
|
+
includeTransferTool?: boolean;
|
|
75
|
+
includeHandoffs?: boolean;
|
|
76
|
+
}): Record<string, Tool>;
|
|
77
|
+
clone(agent?: Omit<Partial<CreateAgent<Output, C>>, 'handoffs'>): Agent<Output, C>;
|
|
78
|
+
}
|
|
79
|
+
export type Instruction<C> = string | string[] | ((contextVariables?: C) => string);
|
|
80
|
+
export interface PurposeRoutineInstructions {
|
|
81
|
+
purpose: string | string[];
|
|
82
|
+
routine: string[];
|
|
83
|
+
}
|
|
84
|
+
export declare function instructions({ purpose, routine }: PurposeRoutineInstructions): string;
|
|
85
|
+
export declare namespace instructions {
|
|
86
|
+
var swarm: ({ purpose, routine }: PurposeRoutineInstructions) => string;
|
|
87
|
+
var supervisor: ({ purpose, routine, }: PurposeRoutineInstructions) => string;
|
|
88
|
+
var supervisor_subagent: ({ purpose, routine, }: PurposeRoutineInstructions) => string;
|
|
89
|
+
}
|
|
90
|
+
type TransferResult = {
|
|
91
|
+
lastActiveAgent: string;
|
|
92
|
+
currentActiveAgent: string;
|
|
93
|
+
};
|
|
94
|
+
export type TransferTool = {
|
|
95
|
+
output: TransferResult;
|
|
96
|
+
};
|
|
97
|
+
export declare function isTransferToolResult(call: unknown | undefined): call is TransferTool;
|
|
98
|
+
export declare function lastTransferResult(messages: ResponseMessage[]): TransferResult | undefined;
|
|
99
|
+
export {};
|
|
100
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/lib/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,YAAY,EAEjB,KAAK,gBAAgB,EACrB,KAAK,IAAI,EACT,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,OAAO,EAMb,MAAM,IAAI,CAAC;AAGZ,OAAO,CAAC,MAAM,KAAK,CAAC;AASpB,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC7B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CAC7B;AACD,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAE5E,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CACzB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,QAAQ,EAAE,YAAY,EAAE,KACrB,OAAO,CAAC,CAAC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AA;CAAE,CAAC;AAC9E,MAAM,MAAM,YAAY,GAAG;IAAE,MAAM,EAAE,cAAc,CAAA;CAAE,CAAC;AACtD,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,OAAO,GAAG,SAAS,GACxB,IAAI,IAAI,YAAY,CAiBtB;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,eAAe,EAAE,8BAgB7D"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Tool } from 'ai';
|
|
2
|
+
import { type Agent, type AgentModel } from '../agent.ts';
|
|
3
|
+
export declare const SYSTEM_PROMPT_DEEPAGENTS: string;
|
|
4
|
+
export type SubAgent = {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
prompt: string;
|
|
8
|
+
tools?: string[];
|
|
9
|
+
model_settings?: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
export declare function create_deep_agent(tools: Record<string, Tool>, prompt: string, model: AgentModel, subagents?: SubAgent[]): Agent<unknown, import("../agent.ts").ContextVariables>;
|
|
12
|
+
//# sourceMappingURL=deepagents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepagents.d.ts","sourceRoot":"","sources":["../../../src/lib/blog/deepagents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAe,MAAM,IAAI,CAAC;AAG5C,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,UAAU,EAAuB,MAAM,aAAa,CAAC;AAkJ/E,eAAO,MAAM,wBAAwB,QAI7B,CAAC;AAGT,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EAC3B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,UAAU,EACjB,SAAS,CAAC,EAAE,QAAQ,EAAE,0DAwEvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docker.d.ts","sourceRoot":"","sources":["../../../src/lib/blog/docker.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,KAAK,EAAuB,MAAM,aAAa,CAAC;AAM9D,eAAO,MAAM,aAAa,QAIlB,CAAC;AA0dT,eAAO,MAAM,mBAAmB,EAAE,KAyBhC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh.d.ts","sourceRoot":"","sources":["../../../src/lib/blog/mesh.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,KAAK,EAAuB,MAAM,aAAa,CAAC;AAE9D,eAAO,MAAM,aAAa,QAMlB,CAAC;AAyDT,eAAO,MAAM,MAAM,wDA8BjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-star.d.ts","sourceRoot":"","sources":["../../../src/lib/blog/package-star.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,KAAK,EAAuB,MAAM,aAAa,CAAC;AAI9D,eAAO,MAAM,aAAa,QAQlB,CAAC;AAgQT,eAAO,MAAM,YAAY,EAAE,KAmCzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"research.d.ts","sourceRoot":"","sources":["../../../src/lib/blog/research.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,QAAQ,EAAuB,MAAM,aAAa,CAAC;AAEjE,eAAO,MAAM,sBAAsB,QAI3B,CAAC;AA4FT,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,UAAU,QAAQ,CAAC,CAAC,CAAC,4CA8BlD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"star.d.ts","sourceRoot":"","sources":["../../../src/lib/blog/star.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,KAAK,EAAuB,MAAM,aAAa,CAAC;AAE9D,eAAO,MAAM,aAAa,QAGlB,CAAC;AA+DT,eAAO,MAAM,cAAc,EAAE,KAiC3B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"animated_svg.d.ts","sourceRoot":"","sources":["../../../src/lib/examples/animated_svg.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finanicals_bot.d.ts","sourceRoot":"","sources":["../../../src/lib/examples/finanicals_bot.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan_and_act_example.d.ts","sourceRoot":"","sources":["../../../src/lib/examples/plan_and_act_example.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Listr, type ListrTask } from 'listr2';
|
|
2
|
+
/**
|
|
3
|
+
* Common progress message sets for typical operations
|
|
4
|
+
*/
|
|
5
|
+
export declare const ProgressMessages: {
|
|
6
|
+
WRITING: string[];
|
|
7
|
+
ANALYZING: string[];
|
|
8
|
+
SEARCHING: string[];
|
|
9
|
+
PROCESSING: string[];
|
|
10
|
+
};
|
|
11
|
+
export declare function createProgress<Ctx>(...tasks: ListrTask<Ctx>[]): Listr<Ctx, "default", "simple">;
|
|
12
|
+
export declare function withMessageProgress(update: (message: string) => void): {
|
|
13
|
+
[Symbol.dispose]: () => void;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=planner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner.d.ts","sourceRoot":"","sources":["../../../src/lib/examples/planner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE/C;;GAEG;AACH,eAAO,MAAM,gBAAgB;aAKtB,MAAM,EAAE;eAKR,MAAM,EAAE;eAKR,MAAM,EAAE;gBAKR,MAAM,EAAE;CACd,CAAC;AAEF,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,mCAM7D;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI;;EAYpE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"research_bot.d.ts","sourceRoot":"","sources":["../../../src/lib/examples/research_bot.ts"],"names":[],"mappings":""}
|