overai 1.4.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/README.md +248 -0
- package/dist/agent/context.d.ts +74 -0
- package/dist/agent/context.js +140 -0
- package/dist/agent/enhanced.d.ts +98 -0
- package/dist/agent/enhanced.js +293 -0
- package/dist/agent/handoff.d.ts +82 -0
- package/dist/agent/handoff.js +124 -0
- package/dist/agent/image.d.ts +57 -0
- package/dist/agent/image.js +116 -0
- package/dist/agent/index.d.ts +19 -0
- package/dist/agent/index.js +38 -0
- package/dist/agent/prompt-expander.d.ts +43 -0
- package/dist/agent/prompt-expander.js +99 -0
- package/dist/agent/proxy.d.ts +26 -0
- package/dist/agent/proxy.js +173 -0
- package/dist/agent/query-rewriter.d.ts +41 -0
- package/dist/agent/query-rewriter.js +94 -0
- package/dist/agent/research.d.ts +55 -0
- package/dist/agent/research.js +134 -0
- package/dist/agent/router.d.ts +141 -0
- package/dist/agent/router.js +209 -0
- package/dist/agent/simple.d.ts +289 -0
- package/dist/agent/simple.js +696 -0
- package/dist/agent/types.d.ts +56 -0
- package/dist/agent/types.js +165 -0
- package/dist/ai/agent-loop.d.ts +177 -0
- package/dist/ai/agent-loop.js +313 -0
- package/dist/ai/devtools.d.ts +74 -0
- package/dist/ai/devtools.js +216 -0
- package/dist/ai/embed.d.ts +71 -0
- package/dist/ai/embed.js +154 -0
- package/dist/ai/generate-image.d.ts +66 -0
- package/dist/ai/generate-image.js +138 -0
- package/dist/ai/generate-object.d.ts +132 -0
- package/dist/ai/generate-object.js +206 -0
- package/dist/ai/generate-text.d.ts +201 -0
- package/dist/ai/generate-text.js +253 -0
- package/dist/ai/index.d.ts +27 -0
- package/dist/ai/index.js +140 -0
- package/dist/ai/mcp.d.ts +181 -0
- package/dist/ai/mcp.js +234 -0
- package/dist/ai/middleware.d.ts +110 -0
- package/dist/ai/middleware.js +186 -0
- package/dist/ai/models.d.ts +67 -0
- package/dist/ai/models.js +249 -0
- package/dist/ai/multimodal.d.ts +125 -0
- package/dist/ai/multimodal.js +270 -0
- package/dist/ai/nextjs.d.ts +122 -0
- package/dist/ai/nextjs.js +218 -0
- package/dist/ai/server.d.ts +126 -0
- package/dist/ai/server.js +336 -0
- package/dist/ai/speech.d.ts +135 -0
- package/dist/ai/speech.js +296 -0
- package/dist/ai/telemetry.d.ts +162 -0
- package/dist/ai/telemetry.js +311 -0
- package/dist/ai/tool-approval.d.ts +225 -0
- package/dist/ai/tool-approval.js +407 -0
- package/dist/ai/tools.d.ts +93 -0
- package/dist/ai/tools.js +89 -0
- package/dist/ai/types.d.ts +47 -0
- package/dist/ai/types.js +5 -0
- package/dist/ai/ui-message.d.ts +218 -0
- package/dist/ai/ui-message.js +291 -0
- package/dist/auto/index.d.ts +62 -0
- package/dist/auto/index.js +163 -0
- package/dist/cache/index.d.ts +78 -0
- package/dist/cache/index.js +235 -0
- package/dist/cli/commands/agent.d.ts +30 -0
- package/dist/cli/commands/agent.js +151 -0
- package/dist/cli/commands/agents.d.ts +24 -0
- package/dist/cli/commands/agents.js +166 -0
- package/dist/cli/commands/approval.d.ts +10 -0
- package/dist/cli/commands/approval.js +253 -0
- package/dist/cli/commands/auto.d.ts +12 -0
- package/dist/cli/commands/auto.js +109 -0
- package/dist/cli/commands/autonomy.d.ts +5 -0
- package/dist/cli/commands/autonomy.js +152 -0
- package/dist/cli/commands/benchmark.d.ts +19 -0
- package/dist/cli/commands/benchmark.js +484 -0
- package/dist/cli/commands/cache.d.ts +9 -0
- package/dist/cli/commands/cache.js +143 -0
- package/dist/cli/commands/chat.d.ts +14 -0
- package/dist/cli/commands/chat.js +127 -0
- package/dist/cli/commands/checkpoints.d.ts +5 -0
- package/dist/cli/commands/checkpoints.js +236 -0
- package/dist/cli/commands/context.d.ts +11 -0
- package/dist/cli/commands/context.js +182 -0
- package/dist/cli/commands/cost.d.ts +5 -0
- package/dist/cli/commands/cost.js +146 -0
- package/dist/cli/commands/db.d.ts +9 -0
- package/dist/cli/commands/db.js +149 -0
- package/dist/cli/commands/embed.d.ts +20 -0
- package/dist/cli/commands/embed.js +375 -0
- package/dist/cli/commands/eval.d.ts +17 -0
- package/dist/cli/commands/eval.js +247 -0
- package/dist/cli/commands/external-agents.d.ts +5 -0
- package/dist/cli/commands/external-agents.js +170 -0
- package/dist/cli/commands/fast-context.d.ts +5 -0
- package/dist/cli/commands/fast-context.js +126 -0
- package/dist/cli/commands/flow.d.ts +5 -0
- package/dist/cli/commands/flow.js +141 -0
- package/dist/cli/commands/git.d.ts +5 -0
- package/dist/cli/commands/git.js +178 -0
- package/dist/cli/commands/graph-rag.d.ts +9 -0
- package/dist/cli/commands/graph-rag.js +131 -0
- package/dist/cli/commands/guardrail.d.ts +11 -0
- package/dist/cli/commands/guardrail.js +156 -0
- package/dist/cli/commands/handoff.d.ts +9 -0
- package/dist/cli/commands/handoff.js +133 -0
- package/dist/cli/commands/help.d.ts +8 -0
- package/dist/cli/commands/help.js +139 -0
- package/dist/cli/commands/image.d.ts +13 -0
- package/dist/cli/commands/image.js +192 -0
- package/dist/cli/commands/interactive.d.ts +6 -0
- package/dist/cli/commands/interactive.js +79 -0
- package/dist/cli/commands/jobs.d.ts +5 -0
- package/dist/cli/commands/jobs.js +282 -0
- package/dist/cli/commands/knowledge.d.ts +9 -0
- package/dist/cli/commands/knowledge.js +226 -0
- package/dist/cli/commands/llm.d.ts +21 -0
- package/dist/cli/commands/llm.js +748 -0
- package/dist/cli/commands/mcp.d.ts +9 -0
- package/dist/cli/commands/mcp.js +243 -0
- package/dist/cli/commands/memory.d.ts +10 -0
- package/dist/cli/commands/memory.js +198 -0
- package/dist/cli/commands/n8n.d.ts +5 -0
- package/dist/cli/commands/n8n.js +137 -0
- package/dist/cli/commands/observability.d.ts +16 -0
- package/dist/cli/commands/observability.js +335 -0
- package/dist/cli/commands/planning.d.ts +9 -0
- package/dist/cli/commands/planning.js +167 -0
- package/dist/cli/commands/prompt-expand.d.ts +11 -0
- package/dist/cli/commands/prompt-expand.js +100 -0
- package/dist/cli/commands/providers.d.ts +17 -0
- package/dist/cli/commands/providers.js +386 -0
- package/dist/cli/commands/query-rewrite.d.ts +12 -0
- package/dist/cli/commands/query-rewrite.js +102 -0
- package/dist/cli/commands/repo-map.d.ts +5 -0
- package/dist/cli/commands/repo-map.js +151 -0
- package/dist/cli/commands/reranker.d.ts +10 -0
- package/dist/cli/commands/reranker.js +144 -0
- package/dist/cli/commands/research.d.ts +12 -0
- package/dist/cli/commands/research.js +108 -0
- package/dist/cli/commands/router.d.ts +11 -0
- package/dist/cli/commands/router.js +142 -0
- package/dist/cli/commands/run.d.ts +14 -0
- package/dist/cli/commands/run.js +111 -0
- package/dist/cli/commands/sandbox.d.ts +5 -0
- package/dist/cli/commands/sandbox.js +135 -0
- package/dist/cli/commands/scheduler.d.ts +5 -0
- package/dist/cli/commands/scheduler.js +260 -0
- package/dist/cli/commands/session.d.ts +9 -0
- package/dist/cli/commands/session.js +238 -0
- package/dist/cli/commands/skills.d.ts +9 -0
- package/dist/cli/commands/skills.js +256 -0
- package/dist/cli/commands/telemetry.d.ts +9 -0
- package/dist/cli/commands/telemetry.js +146 -0
- package/dist/cli/commands/tools.d.ts +19 -0
- package/dist/cli/commands/tools.js +576 -0
- package/dist/cli/commands/vector.d.ts +10 -0
- package/dist/cli/commands/vector.js +171 -0
- package/dist/cli/commands/version.d.ts +8 -0
- package/dist/cli/commands/version.js +40 -0
- package/dist/cli/commands/voice.d.ts +10 -0
- package/dist/cli/commands/voice.js +162 -0
- package/dist/cli/commands/workflow.d.ts +13 -0
- package/dist/cli/commands/workflow.js +184 -0
- package/dist/cli/config/index.d.ts +6 -0
- package/dist/cli/config/index.js +22 -0
- package/dist/cli/config/load.d.ts +20 -0
- package/dist/cli/config/load.js +229 -0
- package/dist/cli/config/resolve.d.ts +28 -0
- package/dist/cli/config/resolve.js +70 -0
- package/dist/cli/config/schema.d.ts +15 -0
- package/dist/cli/config/schema.js +65 -0
- package/dist/cli/features/autonomy-mode.d.ts +98 -0
- package/dist/cli/features/autonomy-mode.js +266 -0
- package/dist/cli/features/background-jobs.d.ts +155 -0
- package/dist/cli/features/background-jobs.js +416 -0
- package/dist/cli/features/checkpoints.d.ts +126 -0
- package/dist/cli/features/checkpoints.js +288 -0
- package/dist/cli/features/cost-tracker.d.ts +101 -0
- package/dist/cli/features/cost-tracker.js +212 -0
- package/dist/cli/features/external-agents.d.ts +117 -0
- package/dist/cli/features/external-agents.js +296 -0
- package/dist/cli/features/fast-context.d.ts +126 -0
- package/dist/cli/features/fast-context.js +310 -0
- package/dist/cli/features/flow-display.d.ts +100 -0
- package/dist/cli/features/flow-display.js +254 -0
- package/dist/cli/features/git-integration.d.ts +138 -0
- package/dist/cli/features/git-integration.js +374 -0
- package/dist/cli/features/index.d.ts +17 -0
- package/dist/cli/features/index.js +102 -0
- package/dist/cli/features/interactive-tui.d.ts +114 -0
- package/dist/cli/features/interactive-tui.js +326 -0
- package/dist/cli/features/n8n-integration.d.ts +111 -0
- package/dist/cli/features/n8n-integration.js +299 -0
- package/dist/cli/features/repo-map.d.ts +101 -0
- package/dist/cli/features/repo-map.js +350 -0
- package/dist/cli/features/sandbox-executor.d.ts +89 -0
- package/dist/cli/features/sandbox-executor.js +314 -0
- package/dist/cli/features/scheduler.d.ts +111 -0
- package/dist/cli/features/scheduler.js +298 -0
- package/dist/cli/features/slash-commands.d.ts +77 -0
- package/dist/cli/features/slash-commands.js +316 -0
- package/dist/cli/index.d.ts +24 -0
- package/dist/cli/index.js +214 -0
- package/dist/cli/output/errors.d.ts +23 -0
- package/dist/cli/output/errors.js +36 -0
- package/dist/cli/output/json.d.ts +27 -0
- package/dist/cli/output/json.js +31 -0
- package/dist/cli/output/pretty.d.ts +13 -0
- package/dist/cli/output/pretty.js +31 -0
- package/dist/cli/runtime/env.d.ts +12 -0
- package/dist/cli/runtime/env.js +55 -0
- package/dist/cli/runtime/exit.d.ts +11 -0
- package/dist/cli/runtime/exit.js +49 -0
- package/dist/cli/runtime/index.d.ts +6 -0
- package/dist/cli/runtime/index.js +22 -0
- package/dist/cli/runtime/lazy.d.ts +18 -0
- package/dist/cli/runtime/lazy.js +85 -0
- package/dist/cli/spec/cli-spec.d.ts +87 -0
- package/dist/cli/spec/cli-spec.js +551 -0
- package/dist/cli/spec/index.d.ts +4 -0
- package/dist/cli/spec/index.js +20 -0
- package/dist/db/index.d.ts +6 -0
- package/dist/db/index.js +75 -0
- package/dist/db/types.d.ts +42 -0
- package/dist/db/types.js +2 -0
- package/dist/eval/index.d.ts +61 -0
- package/dist/eval/index.js +157 -0
- package/dist/events/index.d.ts +84 -0
- package/dist/events/index.js +153 -0
- package/dist/guardrails/index.d.ts +82 -0
- package/dist/guardrails/index.js +202 -0
- package/dist/guardrails/llm-guardrail.d.ts +46 -0
- package/dist/guardrails/llm-guardrail.js +112 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.js +608 -0
- package/dist/integrations/computer-use.d.ts +182 -0
- package/dist/integrations/computer-use.js +356 -0
- package/dist/integrations/index.d.ts +7 -0
- package/dist/integrations/index.js +26 -0
- package/dist/integrations/observability/base.d.ts +123 -0
- package/dist/integrations/observability/base.js +183 -0
- package/dist/integrations/observability/index.d.ts +8 -0
- package/dist/integrations/observability/index.js +29 -0
- package/dist/integrations/observability/langfuse.d.ts +32 -0
- package/dist/integrations/observability/langfuse.js +174 -0
- package/dist/integrations/postgres.d.ts +162 -0
- package/dist/integrations/postgres.js +396 -0
- package/dist/integrations/slack.d.ts +145 -0
- package/dist/integrations/slack.js +270 -0
- package/dist/integrations/vector/base.d.ts +110 -0
- package/dist/integrations/vector/base.js +158 -0
- package/dist/integrations/vector/chroma.d.ts +25 -0
- package/dist/integrations/vector/chroma.js +143 -0
- package/dist/integrations/vector/index.d.ts +14 -0
- package/dist/integrations/vector/index.js +37 -0
- package/dist/integrations/vector/pinecone.d.ts +28 -0
- package/dist/integrations/vector/pinecone.js +172 -0
- package/dist/integrations/vector/qdrant.d.ts +25 -0
- package/dist/integrations/vector/qdrant.js +146 -0
- package/dist/integrations/vector/weaviate.d.ts +30 -0
- package/dist/integrations/vector/weaviate.js +206 -0
- package/dist/integrations/voice/base.d.ts +76 -0
- package/dist/integrations/voice/base.js +168 -0
- package/dist/integrations/voice/index.d.ts +6 -0
- package/dist/integrations/voice/index.js +26 -0
- package/dist/knowledge/chunking.d.ts +55 -0
- package/dist/knowledge/chunking.js +158 -0
- package/dist/knowledge/graph-rag.d.ts +125 -0
- package/dist/knowledge/graph-rag.js +289 -0
- package/dist/knowledge/index.d.ts +24 -0
- package/dist/knowledge/index.js +47 -0
- package/dist/knowledge/knowledge.d.ts +0 -0
- package/dist/knowledge/knowledge.js +1 -0
- package/dist/knowledge/rag.d.ts +80 -0
- package/dist/knowledge/rag.js +147 -0
- package/dist/knowledge/reranker.d.ts +86 -0
- package/dist/knowledge/reranker.js +196 -0
- package/dist/llm/backend-resolver.d.ts +77 -0
- package/dist/llm/backend-resolver.js +242 -0
- package/dist/llm/embeddings.d.ts +66 -0
- package/dist/llm/embeddings.js +294 -0
- package/dist/llm/index.d.ts +29 -0
- package/dist/llm/index.js +33 -0
- package/dist/llm/llm.d.ts +0 -0
- package/dist/llm/llm.js +1 -0
- package/dist/llm/openai.d.ts +39 -0
- package/dist/llm/openai.js +302 -0
- package/dist/llm/providers/ai-sdk/adapter.d.ts +121 -0
- package/dist/llm/providers/ai-sdk/adapter.js +399 -0
- package/dist/llm/providers/ai-sdk/backend.d.ts +49 -0
- package/dist/llm/providers/ai-sdk/backend.js +421 -0
- package/dist/llm/providers/ai-sdk/index.d.ts +69 -0
- package/dist/llm/providers/ai-sdk/index.js +200 -0
- package/dist/llm/providers/ai-sdk/middleware.d.ts +60 -0
- package/dist/llm/providers/ai-sdk/middleware.js +262 -0
- package/dist/llm/providers/ai-sdk/provider-map.d.ts +75 -0
- package/dist/llm/providers/ai-sdk/provider-map.js +258 -0
- package/dist/llm/providers/ai-sdk/types.d.ts +217 -0
- package/dist/llm/providers/ai-sdk/types.js +222 -0
- package/dist/llm/providers/anthropic.d.ts +33 -0
- package/dist/llm/providers/anthropic.js +291 -0
- package/dist/llm/providers/base.d.ts +25 -0
- package/dist/llm/providers/base.js +43 -0
- package/dist/llm/providers/google.d.ts +27 -0
- package/dist/llm/providers/google.js +275 -0
- package/dist/llm/providers/index.d.ts +107 -0
- package/dist/llm/providers/index.js +216 -0
- package/dist/llm/providers/openai.d.ts +18 -0
- package/dist/llm/providers/openai.js +203 -0
- package/dist/llm/providers/registry.d.ts +159 -0
- package/dist/llm/providers/registry.js +279 -0
- package/dist/llm/providers/types.d.ts +94 -0
- package/dist/llm/providers/types.js +5 -0
- package/dist/main.d.ts +0 -0
- package/dist/main.js +1 -0
- package/dist/memory/auto-memory.d.ts +136 -0
- package/dist/memory/auto-memory.js +301 -0
- package/dist/memory/file-memory.d.ts +88 -0
- package/dist/memory/file-memory.js +287 -0
- package/dist/memory/index.d.ts +26 -0
- package/dist/memory/index.js +41 -0
- package/dist/memory/memory.d.ts +92 -0
- package/dist/memory/memory.js +170 -0
- package/dist/observability/adapters/console.d.ts +33 -0
- package/dist/observability/adapters/console.js +71 -0
- package/dist/observability/adapters/external/arize.d.ts +20 -0
- package/dist/observability/adapters/external/arize.js +22 -0
- package/dist/observability/adapters/external/axiom.d.ts +20 -0
- package/dist/observability/adapters/external/axiom.js +22 -0
- package/dist/observability/adapters/external/braintrust.d.ts +20 -0
- package/dist/observability/adapters/external/braintrust.js +22 -0
- package/dist/observability/adapters/external/helicone.d.ts +20 -0
- package/dist/observability/adapters/external/helicone.js +22 -0
- package/dist/observability/adapters/external/laminar.d.ts +20 -0
- package/dist/observability/adapters/external/laminar.js +22 -0
- package/dist/observability/adapters/external/langfuse.d.ts +28 -0
- package/dist/observability/adapters/external/langfuse.js +186 -0
- package/dist/observability/adapters/external/langsmith.d.ts +21 -0
- package/dist/observability/adapters/external/langsmith.js +83 -0
- package/dist/observability/adapters/external/langwatch.d.ts +20 -0
- package/dist/observability/adapters/external/langwatch.js +22 -0
- package/dist/observability/adapters/external/maxim.d.ts +20 -0
- package/dist/observability/adapters/external/maxim.js +22 -0
- package/dist/observability/adapters/external/patronus.d.ts +20 -0
- package/dist/observability/adapters/external/patronus.js +22 -0
- package/dist/observability/adapters/external/scorecard.d.ts +20 -0
- package/dist/observability/adapters/external/scorecard.js +22 -0
- package/dist/observability/adapters/external/signoz.d.ts +20 -0
- package/dist/observability/adapters/external/signoz.js +22 -0
- package/dist/observability/adapters/external/traceloop.d.ts +20 -0
- package/dist/observability/adapters/external/traceloop.js +22 -0
- package/dist/observability/adapters/external/weave.d.ts +20 -0
- package/dist/observability/adapters/external/weave.js +22 -0
- package/dist/observability/adapters/index.d.ts +19 -0
- package/dist/observability/adapters/index.js +289 -0
- package/dist/observability/adapters/memory.d.ts +41 -0
- package/dist/observability/adapters/memory.js +190 -0
- package/dist/observability/adapters/noop.d.ts +25 -0
- package/dist/observability/adapters/noop.js +64 -0
- package/dist/observability/index.d.ts +47 -0
- package/dist/observability/index.js +115 -0
- package/dist/observability/types.d.ts +165 -0
- package/dist/observability/types.js +165 -0
- package/dist/planning/index.d.ts +253 -0
- package/dist/planning/index.js +475 -0
- package/dist/process/index.d.ts +25 -0
- package/dist/process/index.js +37 -0
- package/dist/process/process.d.ts +0 -0
- package/dist/process/process.js +1 -0
- package/dist/session/index.d.ts +111 -0
- package/dist/session/index.js +250 -0
- package/dist/skills/index.d.ts +70 -0
- package/dist/skills/index.js +233 -0
- package/dist/task/index.d.ts +25 -0
- package/dist/task/index.js +32 -0
- package/dist/task/task.d.ts +0 -0
- package/dist/task/task.js +1 -0
- package/dist/telemetry/index.d.ts +175 -0
- package/dist/telemetry/index.js +287 -0
- package/dist/tools/arxivTools.d.ts +32 -0
- package/dist/tools/arxivTools.js +81 -0
- package/dist/tools/base.d.ts +97 -0
- package/dist/tools/base.js +147 -0
- package/dist/tools/builtins/airweave.d.ts +32 -0
- package/dist/tools/builtins/airweave.js +119 -0
- package/dist/tools/builtins/bedrock-agentcore.d.ts +62 -0
- package/dist/tools/builtins/bedrock-agentcore.js +233 -0
- package/dist/tools/builtins/code-execution.d.ts +36 -0
- package/dist/tools/builtins/code-execution.js +136 -0
- package/dist/tools/builtins/code-mode.d.ts +54 -0
- package/dist/tools/builtins/code-mode.js +167 -0
- package/dist/tools/builtins/custom.d.ts +42 -0
- package/dist/tools/builtins/custom.js +195 -0
- package/dist/tools/builtins/exa.d.ts +53 -0
- package/dist/tools/builtins/exa.js +112 -0
- package/dist/tools/builtins/firecrawl.d.ts +56 -0
- package/dist/tools/builtins/firecrawl.js +158 -0
- package/dist/tools/builtins/index.d.ts +45 -0
- package/dist/tools/builtins/index.js +180 -0
- package/dist/tools/builtins/parallel.d.ts +30 -0
- package/dist/tools/builtins/parallel.js +113 -0
- package/dist/tools/builtins/perplexity.d.ts +32 -0
- package/dist/tools/builtins/perplexity.js +113 -0
- package/dist/tools/builtins/superagent.d.ts +66 -0
- package/dist/tools/builtins/superagent.js +187 -0
- package/dist/tools/builtins/tavily.d.ts +99 -0
- package/dist/tools/builtins/tavily.js +285 -0
- package/dist/tools/builtins/valyu.d.ts +65 -0
- package/dist/tools/builtins/valyu.js +193 -0
- package/dist/tools/decorator.d.ts +91 -0
- package/dist/tools/decorator.js +165 -0
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.js +36 -0
- package/dist/tools/mcpSse.d.ts +43 -0
- package/dist/tools/mcpSse.js +110 -0
- package/dist/tools/registry/index.d.ts +9 -0
- package/dist/tools/registry/index.js +28 -0
- package/dist/tools/registry/middleware.d.ts +43 -0
- package/dist/tools/registry/middleware.js +220 -0
- package/dist/tools/registry/registry.d.ts +92 -0
- package/dist/tools/registry/registry.js +280 -0
- package/dist/tools/registry/types.d.ts +217 -0
- package/dist/tools/registry/types.js +49 -0
- package/dist/tools/test.d.ts +0 -0
- package/dist/tools/test.js +1 -0
- package/dist/tools/tools.d.ts +74 -0
- package/dist/tools/tools.js +133 -0
- package/dist/utils/logger.d.ts +25 -0
- package/dist/utils/logger.js +149 -0
- package/dist/utils/pretty-logger.d.ts +21 -0
- package/dist/utils/pretty-logger.js +248 -0
- package/dist/workflows/index.d.ts +118 -0
- package/dist/workflows/index.js +247 -0
- package/dist/workflows/loop.d.ts +0 -0
- package/dist/workflows/loop.js +1 -0
- package/dist/workflows/yaml-parser.d.ts +48 -0
- package/dist/workflows/yaml-parser.js +304 -0
- package/package.json +119 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export interface TaskConfig {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
expected_output: string;
|
|
5
|
+
agent?: any;
|
|
6
|
+
dependencies?: Task[];
|
|
7
|
+
}
|
|
8
|
+
export declare class Task {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
expected_output: string;
|
|
12
|
+
agent: any;
|
|
13
|
+
dependencies: Task[];
|
|
14
|
+
result: any;
|
|
15
|
+
constructor(config: TaskConfig);
|
|
16
|
+
}
|
|
17
|
+
export interface TaskAgentConfig {
|
|
18
|
+
name: string;
|
|
19
|
+
role: string;
|
|
20
|
+
goal: string;
|
|
21
|
+
backstory: string;
|
|
22
|
+
verbose?: boolean;
|
|
23
|
+
llm?: string;
|
|
24
|
+
markdown?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare class Agent {
|
|
27
|
+
private name;
|
|
28
|
+
private role;
|
|
29
|
+
private goal;
|
|
30
|
+
private backstory;
|
|
31
|
+
private verbose;
|
|
32
|
+
private llm;
|
|
33
|
+
private markdown;
|
|
34
|
+
private result;
|
|
35
|
+
constructor(config: TaskAgentConfig);
|
|
36
|
+
execute(task: Task, dependencyResults?: any[]): Promise<any>;
|
|
37
|
+
}
|
|
38
|
+
export interface TaskPraisonAIAgentsConfig {
|
|
39
|
+
agents: Agent[];
|
|
40
|
+
tasks: Task[];
|
|
41
|
+
verbose?: boolean;
|
|
42
|
+
process?: 'sequential' | 'parallel' | 'hierarchical';
|
|
43
|
+
manager_llm?: string;
|
|
44
|
+
}
|
|
45
|
+
export declare class PraisonAIAgents {
|
|
46
|
+
private agents;
|
|
47
|
+
private tasks;
|
|
48
|
+
private verbose;
|
|
49
|
+
private process;
|
|
50
|
+
private manager_llm;
|
|
51
|
+
constructor(config: TaskPraisonAIAgentsConfig);
|
|
52
|
+
start(): Promise<any[]>;
|
|
53
|
+
private executeSequential;
|
|
54
|
+
private executeHierarchical;
|
|
55
|
+
}
|
|
56
|
+
export type { TaskAgentConfig as AgentConfig };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PraisonAIAgents = exports.Agent = exports.Task = void 0;
|
|
4
|
+
const openai_1 = require("../llm/openai");
|
|
5
|
+
const logger_1 = require("../utils/logger");
|
|
6
|
+
class Task {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.name = config.name;
|
|
9
|
+
this.description = config.description;
|
|
10
|
+
this.expected_output = config.expected_output;
|
|
11
|
+
this.agent = config.agent || null;
|
|
12
|
+
this.dependencies = config.dependencies || [];
|
|
13
|
+
this.result = null;
|
|
14
|
+
logger_1.Logger.debug(`Task created: ${this.name}`, { config });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.Task = Task;
|
|
18
|
+
class Agent {
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.name = config.name;
|
|
21
|
+
this.role = config.role;
|
|
22
|
+
this.goal = config.goal;
|
|
23
|
+
this.backstory = config.backstory;
|
|
24
|
+
this.verbose = config.verbose || false;
|
|
25
|
+
this.llm = new openai_1.OpenAIService(config.llm || 'gpt-5-nano');
|
|
26
|
+
this.markdown = config.markdown || true;
|
|
27
|
+
this.result = '';
|
|
28
|
+
logger_1.Logger.debug(`Agent created: ${this.name}`, { config });
|
|
29
|
+
}
|
|
30
|
+
async execute(task, dependencyResults) {
|
|
31
|
+
logger_1.Logger.debug(`Agent ${this.name} executing task: ${task.name}`, {
|
|
32
|
+
task,
|
|
33
|
+
dependencyResults
|
|
34
|
+
});
|
|
35
|
+
const systemPrompt = `You are ${this.name}, a ${this.role}.
|
|
36
|
+
Your goal is to ${this.goal}.
|
|
37
|
+
Background: ${this.backstory}
|
|
38
|
+
|
|
39
|
+
You must complete the following task:
|
|
40
|
+
Name: ${task.name}
|
|
41
|
+
Description: ${task.description}
|
|
42
|
+
Expected Output: ${task.expected_output}
|
|
43
|
+
|
|
44
|
+
Respond ONLY with the expected output. Do not include any additional text, explanations, or pleasantries.`;
|
|
45
|
+
let prompt = '';
|
|
46
|
+
if (dependencyResults && dependencyResults.length > 0) {
|
|
47
|
+
prompt = `Here are the results from previous tasks that you should use as input:
|
|
48
|
+
${dependencyResults.map((result, index) => `Task ${index + 1} Result:\n${result}`).join('\n\n')}
|
|
49
|
+
|
|
50
|
+
Based on these results, please complete your task.`;
|
|
51
|
+
logger_1.Logger.debug('Using dependency results for prompt', { dependencyResults });
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
prompt = 'Please complete your task.';
|
|
55
|
+
}
|
|
56
|
+
logger_1.Logger.debug('Preparing LLM request', {
|
|
57
|
+
systemPrompt,
|
|
58
|
+
prompt
|
|
59
|
+
});
|
|
60
|
+
if (this.verbose) {
|
|
61
|
+
logger_1.Logger.info(`\nExecuting task for ${this.name}...`);
|
|
62
|
+
logger_1.Logger.info(`Task: ${task.name}`);
|
|
63
|
+
logger_1.Logger.info('Generating response (streaming)...\n');
|
|
64
|
+
}
|
|
65
|
+
// Reset result
|
|
66
|
+
this.result = '';
|
|
67
|
+
// Stream the response and collect it
|
|
68
|
+
await this.llm.streamText(prompt, systemPrompt, 0.7, (token) => {
|
|
69
|
+
if (this.verbose) {
|
|
70
|
+
process.stdout.write(token);
|
|
71
|
+
}
|
|
72
|
+
this.result += token;
|
|
73
|
+
});
|
|
74
|
+
if (this.verbose) {
|
|
75
|
+
console.log('\n'); // Add newline after streaming
|
|
76
|
+
}
|
|
77
|
+
logger_1.Logger.debug(`Agent ${this.name} completed task: ${task.name}`, {
|
|
78
|
+
result: this.result
|
|
79
|
+
});
|
|
80
|
+
return this.result;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.Agent = Agent;
|
|
84
|
+
class PraisonAIAgents {
|
|
85
|
+
constructor(config) {
|
|
86
|
+
this.agents = config.agents;
|
|
87
|
+
this.tasks = config.tasks;
|
|
88
|
+
this.verbose = config.verbose || false;
|
|
89
|
+
this.process = config.process || 'sequential';
|
|
90
|
+
this.manager_llm = config.manager_llm || 'gpt-5-nano';
|
|
91
|
+
logger_1.Logger.debug('PraisonAIAgents initialized', { config });
|
|
92
|
+
}
|
|
93
|
+
async start() {
|
|
94
|
+
logger_1.Logger.debug('Starting PraisonAI Agents execution...');
|
|
95
|
+
logger_1.Logger.debug('Starting with process mode:', this.process);
|
|
96
|
+
let results;
|
|
97
|
+
switch (this.process) {
|
|
98
|
+
case 'parallel':
|
|
99
|
+
logger_1.Logger.debug('Executing tasks in parallel');
|
|
100
|
+
results = await Promise.all(this.tasks.map(task => {
|
|
101
|
+
if (!task.agent)
|
|
102
|
+
throw new Error(`No agent assigned to task: ${task.name}`);
|
|
103
|
+
return task.agent.execute(task);
|
|
104
|
+
}));
|
|
105
|
+
break;
|
|
106
|
+
case 'hierarchical':
|
|
107
|
+
logger_1.Logger.debug('Executing tasks hierarchically');
|
|
108
|
+
results = await this.executeHierarchical();
|
|
109
|
+
break;
|
|
110
|
+
default:
|
|
111
|
+
logger_1.Logger.debug('Executing tasks sequentially');
|
|
112
|
+
results = await this.executeSequential();
|
|
113
|
+
}
|
|
114
|
+
if (this.verbose) {
|
|
115
|
+
logger_1.Logger.info('\nPraisonAI Agents execution completed.');
|
|
116
|
+
results.forEach((result, index) => {
|
|
117
|
+
logger_1.Logger.info(`\nFinal Result from Task ${index + 1}:`);
|
|
118
|
+
console.log(result);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
logger_1.Logger.debug('Execution completed', { results });
|
|
122
|
+
return results;
|
|
123
|
+
}
|
|
124
|
+
async executeSequential() {
|
|
125
|
+
logger_1.Logger.debug('Starting sequential execution');
|
|
126
|
+
const results = [];
|
|
127
|
+
for (const task of this.tasks) {
|
|
128
|
+
if (!task.agent)
|
|
129
|
+
throw new Error(`No agent assigned to task: ${task.name}`);
|
|
130
|
+
logger_1.Logger.debug(`Executing task: ${task.name}`);
|
|
131
|
+
const result = await task.agent.execute(task);
|
|
132
|
+
results.push(result);
|
|
133
|
+
task.result = result;
|
|
134
|
+
logger_1.Logger.debug(`Completed task: ${task.name}`, { result });
|
|
135
|
+
}
|
|
136
|
+
return results;
|
|
137
|
+
}
|
|
138
|
+
async executeHierarchical() {
|
|
139
|
+
const startTime = process.env.LOGLEVEL === 'debug' ? Date.now() : 0;
|
|
140
|
+
logger_1.Logger.debug('Starting hierarchical execution');
|
|
141
|
+
const results = [];
|
|
142
|
+
for (const task of this.tasks) {
|
|
143
|
+
const taskStartTime = process.env.LOGLEVEL === 'debug' ? Date.now() : 0;
|
|
144
|
+
if (!task.agent)
|
|
145
|
+
throw new Error(`No agent assigned to task: ${task.name}`);
|
|
146
|
+
logger_1.Logger.debug(`Executing task: ${task.name}`, {
|
|
147
|
+
dependencies: task.dependencies.map(d => d.name)
|
|
148
|
+
});
|
|
149
|
+
const depResults = task.dependencies.map(dep => dep.result);
|
|
150
|
+
logger_1.Logger.debug(`Dependency results for task ${task.name}`, { depResults });
|
|
151
|
+
const result = await task.agent.execute(task, depResults);
|
|
152
|
+
results.push(result);
|
|
153
|
+
task.result = result;
|
|
154
|
+
if (process.env.LOGLEVEL === 'debug') {
|
|
155
|
+
logger_1.Logger.debug(`Task execution time for ${task.name}: ${Date.now() - taskStartTime}ms`);
|
|
156
|
+
}
|
|
157
|
+
logger_1.Logger.debug(`Completed task: ${task.name}`, { result });
|
|
158
|
+
}
|
|
159
|
+
if (process.env.LOGLEVEL === 'debug') {
|
|
160
|
+
logger_1.Logger.debug(`Total hierarchical execution time: ${Date.now() - startTime}ms`);
|
|
161
|
+
}
|
|
162
|
+
return results;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.PraisonAIAgents = PraisonAIAgents;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Loop - Manual Agent Loop Control
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for manual control of agent execution loops.
|
|
5
|
+
*/
|
|
6
|
+
import type { Message } from './types';
|
|
7
|
+
export interface AgentLoopConfig {
|
|
8
|
+
/** Model to use */
|
|
9
|
+
model: string;
|
|
10
|
+
/** System prompt */
|
|
11
|
+
system?: string;
|
|
12
|
+
/** Available tools */
|
|
13
|
+
tools?: Record<string, AgentTool>;
|
|
14
|
+
/** Maximum steps (default: 10) */
|
|
15
|
+
maxSteps?: number;
|
|
16
|
+
/** Stop condition */
|
|
17
|
+
stopWhen?: StopCondition;
|
|
18
|
+
/** On step finish callback */
|
|
19
|
+
onStepFinish?: (step: AgentStep) => void | Promise<void>;
|
|
20
|
+
/** On tool call callback (for approval) */
|
|
21
|
+
onToolCall?: (toolCall: ToolCallInfo) => Promise<boolean>;
|
|
22
|
+
}
|
|
23
|
+
export interface AgentTool {
|
|
24
|
+
description: string;
|
|
25
|
+
parameters: any;
|
|
26
|
+
execute: (args: any) => Promise<any>;
|
|
27
|
+
}
|
|
28
|
+
export interface AgentStep {
|
|
29
|
+
stepNumber: number;
|
|
30
|
+
text: string;
|
|
31
|
+
toolCalls: ToolCallInfo[];
|
|
32
|
+
toolResults: ToolResultInfo[];
|
|
33
|
+
usage: {
|
|
34
|
+
promptTokens: number;
|
|
35
|
+
completionTokens: number;
|
|
36
|
+
totalTokens: number;
|
|
37
|
+
};
|
|
38
|
+
finishReason: string;
|
|
39
|
+
}
|
|
40
|
+
export interface ToolCallInfo {
|
|
41
|
+
toolCallId: string;
|
|
42
|
+
toolName: string;
|
|
43
|
+
args: any;
|
|
44
|
+
}
|
|
45
|
+
export interface ToolResultInfo {
|
|
46
|
+
toolCallId: string;
|
|
47
|
+
toolName: string;
|
|
48
|
+
result: any;
|
|
49
|
+
isError?: boolean;
|
|
50
|
+
}
|
|
51
|
+
export type StopCondition = {
|
|
52
|
+
type: 'stepCount';
|
|
53
|
+
count: number;
|
|
54
|
+
} | {
|
|
55
|
+
type: 'noToolCalls';
|
|
56
|
+
} | {
|
|
57
|
+
type: 'custom';
|
|
58
|
+
check: (step: AgentStep) => boolean;
|
|
59
|
+
};
|
|
60
|
+
export interface AgentLoopResult {
|
|
61
|
+
text: string;
|
|
62
|
+
steps: AgentStep[];
|
|
63
|
+
totalUsage: {
|
|
64
|
+
promptTokens: number;
|
|
65
|
+
completionTokens: number;
|
|
66
|
+
totalTokens: number;
|
|
67
|
+
};
|
|
68
|
+
finishReason: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create a manual agent loop for fine-grained control.
|
|
72
|
+
*
|
|
73
|
+
* @example Basic usage
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const loop = createAgentLoop({
|
|
76
|
+
* model: 'gpt-4o',
|
|
77
|
+
* system: 'You are a helpful assistant',
|
|
78
|
+
* tools: {
|
|
79
|
+
* search: {
|
|
80
|
+
* description: 'Search the web',
|
|
81
|
+
* parameters: z.object({ query: z.string() }),
|
|
82
|
+
* execute: async ({ query }) => searchWeb(query)
|
|
83
|
+
* }
|
|
84
|
+
* },
|
|
85
|
+
* maxSteps: 5
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* const result = await loop.run('Find information about AI');
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example With approval
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const loop = createAgentLoop({
|
|
94
|
+
* model: 'gpt-4o',
|
|
95
|
+
* tools: { ... },
|
|
96
|
+
* onToolCall: async (toolCall) => {
|
|
97
|
+
* const approved = await askUserForApproval(toolCall);
|
|
98
|
+
* return approved;
|
|
99
|
+
* }
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example Step-by-step control
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const loop = createAgentLoop({ model: 'gpt-4o', tools: { ... } });
|
|
106
|
+
*
|
|
107
|
+
* // Initialize with a prompt
|
|
108
|
+
* loop.addMessage({ role: 'user', content: 'Hello' });
|
|
109
|
+
*
|
|
110
|
+
* // Run one step at a time
|
|
111
|
+
* while (!loop.isComplete()) {
|
|
112
|
+
* const step = await loop.step();
|
|
113
|
+
* console.log('Step:', step);
|
|
114
|
+
*
|
|
115
|
+
* // Optionally modify messages or tools between steps
|
|
116
|
+
* if (needsMoreContext) {
|
|
117
|
+
* loop.addMessage({ role: 'user', content: 'Additional context...' });
|
|
118
|
+
* }
|
|
119
|
+
* }
|
|
120
|
+
*
|
|
121
|
+
* const result = loop.getResult();
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare function createAgentLoop(config: AgentLoopConfig): AgentLoop;
|
|
125
|
+
export declare class AgentLoop {
|
|
126
|
+
private config;
|
|
127
|
+
private messages;
|
|
128
|
+
private steps;
|
|
129
|
+
private currentStep;
|
|
130
|
+
private complete;
|
|
131
|
+
private totalUsage;
|
|
132
|
+
constructor(config: AgentLoopConfig);
|
|
133
|
+
/**
|
|
134
|
+
* Add a message to the conversation.
|
|
135
|
+
*/
|
|
136
|
+
addMessage(message: Message): void;
|
|
137
|
+
/**
|
|
138
|
+
* Get all messages in the conversation.
|
|
139
|
+
*/
|
|
140
|
+
getMessages(): Message[];
|
|
141
|
+
/**
|
|
142
|
+
* Check if the loop is complete.
|
|
143
|
+
*/
|
|
144
|
+
isComplete(): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Run a single step of the agent loop.
|
|
147
|
+
*/
|
|
148
|
+
step(): Promise<AgentStep>;
|
|
149
|
+
/**
|
|
150
|
+
* Run the full agent loop until completion.
|
|
151
|
+
*/
|
|
152
|
+
run(prompt: string): Promise<AgentLoopResult>;
|
|
153
|
+
/**
|
|
154
|
+
* Get the final result.
|
|
155
|
+
*/
|
|
156
|
+
getResult(): AgentLoopResult;
|
|
157
|
+
/**
|
|
158
|
+
* Check if the loop should stop.
|
|
159
|
+
*/
|
|
160
|
+
private shouldStop;
|
|
161
|
+
/**
|
|
162
|
+
* Reset the agent loop.
|
|
163
|
+
*/
|
|
164
|
+
reset(): void;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Create a stop condition that stops after N steps.
|
|
168
|
+
*/
|
|
169
|
+
export declare function stopAfterSteps(count: number): StopCondition;
|
|
170
|
+
/**
|
|
171
|
+
* Create a stop condition that stops when no tool calls are made.
|
|
172
|
+
*/
|
|
173
|
+
export declare function stopWhenNoToolCalls(): StopCondition;
|
|
174
|
+
/**
|
|
175
|
+
* Create a custom stop condition.
|
|
176
|
+
*/
|
|
177
|
+
export declare function stopWhen(check: (step: AgentStep) => boolean): StopCondition;
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Agent Loop - Manual Agent Loop Control
|
|
4
|
+
*
|
|
5
|
+
* Provides utilities for manual control of agent execution loops.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.AgentLoop = void 0;
|
|
42
|
+
exports.createAgentLoop = createAgentLoop;
|
|
43
|
+
exports.stopAfterSteps = stopAfterSteps;
|
|
44
|
+
exports.stopWhenNoToolCalls = stopWhenNoToolCalls;
|
|
45
|
+
exports.stopWhen = stopWhen;
|
|
46
|
+
/**
|
|
47
|
+
* Create a manual agent loop for fine-grained control.
|
|
48
|
+
*
|
|
49
|
+
* @example Basic usage
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const loop = createAgentLoop({
|
|
52
|
+
* model: 'gpt-4o',
|
|
53
|
+
* system: 'You are a helpful assistant',
|
|
54
|
+
* tools: {
|
|
55
|
+
* search: {
|
|
56
|
+
* description: 'Search the web',
|
|
57
|
+
* parameters: z.object({ query: z.string() }),
|
|
58
|
+
* execute: async ({ query }) => searchWeb(query)
|
|
59
|
+
* }
|
|
60
|
+
* },
|
|
61
|
+
* maxSteps: 5
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* const result = await loop.run('Find information about AI');
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @example With approval
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const loop = createAgentLoop({
|
|
70
|
+
* model: 'gpt-4o',
|
|
71
|
+
* tools: { ... },
|
|
72
|
+
* onToolCall: async (toolCall) => {
|
|
73
|
+
* const approved = await askUserForApproval(toolCall);
|
|
74
|
+
* return approved;
|
|
75
|
+
* }
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @example Step-by-step control
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const loop = createAgentLoop({ model: 'gpt-4o', tools: { ... } });
|
|
82
|
+
*
|
|
83
|
+
* // Initialize with a prompt
|
|
84
|
+
* loop.addMessage({ role: 'user', content: 'Hello' });
|
|
85
|
+
*
|
|
86
|
+
* // Run one step at a time
|
|
87
|
+
* while (!loop.isComplete()) {
|
|
88
|
+
* const step = await loop.step();
|
|
89
|
+
* console.log('Step:', step);
|
|
90
|
+
*
|
|
91
|
+
* // Optionally modify messages or tools between steps
|
|
92
|
+
* if (needsMoreContext) {
|
|
93
|
+
* loop.addMessage({ role: 'user', content: 'Additional context...' });
|
|
94
|
+
* }
|
|
95
|
+
* }
|
|
96
|
+
*
|
|
97
|
+
* const result = loop.getResult();
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
function createAgentLoop(config) {
|
|
101
|
+
return new AgentLoop(config);
|
|
102
|
+
}
|
|
103
|
+
class AgentLoop {
|
|
104
|
+
constructor(config) {
|
|
105
|
+
this.messages = [];
|
|
106
|
+
this.steps = [];
|
|
107
|
+
this.currentStep = 0;
|
|
108
|
+
this.complete = false;
|
|
109
|
+
this.totalUsage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
110
|
+
this.config = {
|
|
111
|
+
maxSteps: 10,
|
|
112
|
+
...config,
|
|
113
|
+
};
|
|
114
|
+
// Add system message if provided
|
|
115
|
+
if (config.system) {
|
|
116
|
+
this.messages.push({ role: 'system', content: config.system });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Add a message to the conversation.
|
|
121
|
+
*/
|
|
122
|
+
addMessage(message) {
|
|
123
|
+
this.messages.push(message);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get all messages in the conversation.
|
|
127
|
+
*/
|
|
128
|
+
getMessages() {
|
|
129
|
+
return [...this.messages];
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Check if the loop is complete.
|
|
133
|
+
*/
|
|
134
|
+
isComplete() {
|
|
135
|
+
return this.complete;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Run a single step of the agent loop.
|
|
139
|
+
*/
|
|
140
|
+
async step() {
|
|
141
|
+
if (this.complete) {
|
|
142
|
+
throw new Error('Agent loop is already complete');
|
|
143
|
+
}
|
|
144
|
+
this.currentStep++;
|
|
145
|
+
// Check max steps
|
|
146
|
+
if (this.currentStep > (this.config.maxSteps || 10)) {
|
|
147
|
+
this.complete = true;
|
|
148
|
+
throw new Error(`Maximum steps (${this.config.maxSteps}) reached`);
|
|
149
|
+
}
|
|
150
|
+
// Import and call generateText
|
|
151
|
+
const { generateText } = await Promise.resolve().then(() => __importStar(require('./generate-text')));
|
|
152
|
+
const result = await generateText({
|
|
153
|
+
model: this.config.model,
|
|
154
|
+
messages: this.messages,
|
|
155
|
+
tools: this.config.tools,
|
|
156
|
+
maxSteps: 1, // Single step
|
|
157
|
+
});
|
|
158
|
+
// Build step result
|
|
159
|
+
const step = {
|
|
160
|
+
stepNumber: this.currentStep,
|
|
161
|
+
text: result.text,
|
|
162
|
+
toolCalls: result.toolCalls.map(tc => ({
|
|
163
|
+
toolCallId: tc.toolCallId,
|
|
164
|
+
toolName: tc.toolName,
|
|
165
|
+
args: tc.args,
|
|
166
|
+
})),
|
|
167
|
+
toolResults: result.toolResults.map(tr => ({
|
|
168
|
+
toolCallId: tr.toolCallId,
|
|
169
|
+
toolName: tr.toolName,
|
|
170
|
+
result: tr.result,
|
|
171
|
+
})),
|
|
172
|
+
usage: result.usage,
|
|
173
|
+
finishReason: result.finishReason,
|
|
174
|
+
};
|
|
175
|
+
// Update total usage
|
|
176
|
+
this.totalUsage.promptTokens += result.usage.promptTokens;
|
|
177
|
+
this.totalUsage.completionTokens += result.usage.completionTokens;
|
|
178
|
+
this.totalUsage.totalTokens += result.usage.totalTokens;
|
|
179
|
+
// Add assistant message
|
|
180
|
+
if (result.text) {
|
|
181
|
+
this.messages.push({ role: 'assistant', content: result.text });
|
|
182
|
+
}
|
|
183
|
+
// Handle tool calls
|
|
184
|
+
if (step.toolCalls.length > 0) {
|
|
185
|
+
// Check for approval if callback provided
|
|
186
|
+
if (this.config.onToolCall) {
|
|
187
|
+
for (const toolCall of step.toolCalls) {
|
|
188
|
+
const approved = await this.config.onToolCall(toolCall);
|
|
189
|
+
if (!approved) {
|
|
190
|
+
this.complete = true;
|
|
191
|
+
step.finishReason = 'tool_rejected';
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// Add tool call message
|
|
197
|
+
const toolCallParts = step.toolCalls.map(tc => ({
|
|
198
|
+
type: 'tool-call',
|
|
199
|
+
toolCallId: tc.toolCallId,
|
|
200
|
+
toolName: tc.toolName,
|
|
201
|
+
args: tc.args,
|
|
202
|
+
}));
|
|
203
|
+
this.messages.push({ role: 'assistant', content: '', toolCalls: toolCallParts });
|
|
204
|
+
// Add tool results
|
|
205
|
+
for (const tr of step.toolResults) {
|
|
206
|
+
const toolResultPart = {
|
|
207
|
+
type: 'tool-result',
|
|
208
|
+
toolCallId: tr.toolCallId,
|
|
209
|
+
toolName: tr.toolName,
|
|
210
|
+
result: tr.result,
|
|
211
|
+
};
|
|
212
|
+
this.messages.push({
|
|
213
|
+
role: 'tool',
|
|
214
|
+
content: [toolResultPart],
|
|
215
|
+
toolCallId: tr.toolCallId,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
// Store step
|
|
220
|
+
this.steps.push(step);
|
|
221
|
+
// Call step finish callback
|
|
222
|
+
if (this.config.onStepFinish) {
|
|
223
|
+
await this.config.onStepFinish(step);
|
|
224
|
+
}
|
|
225
|
+
// Check stop conditions
|
|
226
|
+
if (this.shouldStop(step)) {
|
|
227
|
+
this.complete = true;
|
|
228
|
+
}
|
|
229
|
+
return step;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Run the full agent loop until completion.
|
|
233
|
+
*/
|
|
234
|
+
async run(prompt) {
|
|
235
|
+
// Add user message
|
|
236
|
+
this.addMessage({ role: 'user', content: prompt });
|
|
237
|
+
// Run steps until complete
|
|
238
|
+
while (!this.isComplete()) {
|
|
239
|
+
try {
|
|
240
|
+
await this.step();
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
if (error.message.includes('Maximum steps')) {
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return this.getResult();
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Get the final result.
|
|
253
|
+
*/
|
|
254
|
+
getResult() {
|
|
255
|
+
const lastStep = this.steps[this.steps.length - 1];
|
|
256
|
+
return {
|
|
257
|
+
text: lastStep?.text || '',
|
|
258
|
+
steps: this.steps,
|
|
259
|
+
totalUsage: this.totalUsage,
|
|
260
|
+
finishReason: lastStep?.finishReason || 'unknown',
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Check if the loop should stop.
|
|
265
|
+
*/
|
|
266
|
+
shouldStop(step) {
|
|
267
|
+
// Check custom stop condition
|
|
268
|
+
if (this.config.stopWhen) {
|
|
269
|
+
switch (this.config.stopWhen.type) {
|
|
270
|
+
case 'stepCount':
|
|
271
|
+
return this.currentStep >= this.config.stopWhen.count;
|
|
272
|
+
case 'noToolCalls':
|
|
273
|
+
return step.toolCalls.length === 0;
|
|
274
|
+
case 'custom':
|
|
275
|
+
return this.config.stopWhen.check(step);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
// Default: stop when no tool calls
|
|
279
|
+
return step.toolCalls.length === 0 && step.finishReason === 'stop';
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Reset the agent loop.
|
|
283
|
+
*/
|
|
284
|
+
reset() {
|
|
285
|
+
this.messages = [];
|
|
286
|
+
this.steps = [];
|
|
287
|
+
this.currentStep = 0;
|
|
288
|
+
this.complete = false;
|
|
289
|
+
this.totalUsage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
290
|
+
if (this.config.system) {
|
|
291
|
+
this.messages.push({ role: 'system', content: this.config.system });
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
exports.AgentLoop = AgentLoop;
|
|
296
|
+
/**
|
|
297
|
+
* Create a stop condition that stops after N steps.
|
|
298
|
+
*/
|
|
299
|
+
function stopAfterSteps(count) {
|
|
300
|
+
return { type: 'stepCount', count };
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Create a stop condition that stops when no tool calls are made.
|
|
304
|
+
*/
|
|
305
|
+
function stopWhenNoToolCalls() {
|
|
306
|
+
return { type: 'noToolCalls' };
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Create a custom stop condition.
|
|
310
|
+
*/
|
|
311
|
+
function stopWhen(check) {
|
|
312
|
+
return { type: 'custom', check };
|
|
313
|
+
}
|