universal-agent-protocol 0.5.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/LICENSE +21 -0
- package/README.md +462 -0
- package/dist/analyzers/index.d.ts +3 -0
- package/dist/analyzers/index.d.ts.map +1 -0
- package/dist/analyzers/index.js +656 -0
- package/dist/analyzers/index.js.map +1 -0
- package/dist/bin/cli.d.ts +3 -0
- package/dist/bin/cli.d.ts.map +1 -0
- package/dist/bin/cli.js +506 -0
- package/dist/bin/cli.js.map +1 -0
- package/dist/bin/tool-calls.d.ts +3 -0
- package/dist/bin/tool-calls.d.ts.map +1 -0
- package/dist/bin/tool-calls.js +4 -0
- package/dist/bin/tool-calls.js.map +1 -0
- package/dist/cli/agent.d.ts +20 -0
- package/dist/cli/agent.d.ts.map +1 -0
- package/dist/cli/agent.js +434 -0
- package/dist/cli/agent.js.map +1 -0
- package/dist/cli/analyze.d.ts +7 -0
- package/dist/cli/analyze.d.ts.map +1 -0
- package/dist/cli/analyze.js +103 -0
- package/dist/cli/analyze.js.map +1 -0
- package/dist/cli/coord.d.ts +7 -0
- package/dist/cli/coord.d.ts.map +1 -0
- package/dist/cli/coord.js +138 -0
- package/dist/cli/coord.js.map +1 -0
- package/dist/cli/dashboard.d.ts +8 -0
- package/dist/cli/dashboard.d.ts.map +1 -0
- package/dist/cli/dashboard.js +704 -0
- package/dist/cli/dashboard.js.map +1 -0
- package/dist/cli/deploy.d.ts +19 -0
- package/dist/cli/deploy.d.ts.map +1 -0
- package/dist/cli/deploy.js +267 -0
- package/dist/cli/deploy.js.map +1 -0
- package/dist/cli/droids.d.ts +9 -0
- package/dist/cli/droids.d.ts.map +1 -0
- package/dist/cli/droids.js +227 -0
- package/dist/cli/droids.js.map +1 -0
- package/dist/cli/generate.d.ts +17 -0
- package/dist/cli/generate.d.ts.map +1 -0
- package/dist/cli/generate.js +432 -0
- package/dist/cli/generate.js.map +1 -0
- package/dist/cli/hooks.d.ts +9 -0
- package/dist/cli/hooks.d.ts.map +1 -0
- package/dist/cli/hooks.js +374 -0
- package/dist/cli/hooks.js.map +1 -0
- package/dist/cli/init.d.ts +11 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +316 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/mcp-router.d.ts +16 -0
- package/dist/cli/mcp-router.d.ts.map +1 -0
- package/dist/cli/mcp-router.js +143 -0
- package/dist/cli/mcp-router.js.map +1 -0
- package/dist/cli/memory.d.ts +24 -0
- package/dist/cli/memory.d.ts.map +1 -0
- package/dist/cli/memory.js +877 -0
- package/dist/cli/memory.js.map +1 -0
- package/dist/cli/model.d.ts +15 -0
- package/dist/cli/model.d.ts.map +1 -0
- package/dist/cli/model.js +270 -0
- package/dist/cli/model.js.map +1 -0
- package/dist/cli/patterns.d.ts +26 -0
- package/dist/cli/patterns.d.ts.map +1 -0
- package/dist/cli/patterns.js +587 -0
- package/dist/cli/patterns.js.map +1 -0
- package/dist/cli/setup-mcp-router.d.ts +8 -0
- package/dist/cli/setup-mcp-router.d.ts.map +1 -0
- package/dist/cli/setup-mcp-router.js +163 -0
- package/dist/cli/setup-mcp-router.js.map +1 -0
- package/dist/cli/setup.d.ts +13 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +146 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli/sync.d.ts +7 -0
- package/dist/cli/sync.d.ts.map +1 -0
- package/dist/cli/sync.js +26 -0
- package/dist/cli/sync.js.map +1 -0
- package/dist/cli/task.d.ts +33 -0
- package/dist/cli/task.d.ts.map +1 -0
- package/dist/cli/task.js +616 -0
- package/dist/cli/task.js.map +1 -0
- package/dist/cli/tool-calls.d.ts +8 -0
- package/dist/cli/tool-calls.d.ts.map +1 -0
- package/dist/cli/tool-calls.js +239 -0
- package/dist/cli/tool-calls.js.map +1 -0
- package/dist/cli/update.d.ts +10 -0
- package/dist/cli/update.d.ts.map +1 -0
- package/dist/cli/update.js +300 -0
- package/dist/cli/update.js.map +1 -0
- package/dist/cli/visualize.d.ts +77 -0
- package/dist/cli/visualize.d.ts.map +1 -0
- package/dist/cli/visualize.js +287 -0
- package/dist/cli/visualize.js.map +1 -0
- package/dist/cli/worktree.d.ts +9 -0
- package/dist/cli/worktree.d.ts.map +1 -0
- package/dist/cli/worktree.js +175 -0
- package/dist/cli/worktree.js.map +1 -0
- package/dist/coordination/capability-router.d.ts +79 -0
- package/dist/coordination/capability-router.d.ts.map +1 -0
- package/dist/coordination/capability-router.js +324 -0
- package/dist/coordination/capability-router.js.map +1 -0
- package/dist/coordination/database.d.ts +13 -0
- package/dist/coordination/database.d.ts.map +1 -0
- package/dist/coordination/database.js +131 -0
- package/dist/coordination/database.js.map +1 -0
- package/dist/coordination/deploy-batcher.d.ts +101 -0
- package/dist/coordination/deploy-batcher.d.ts.map +1 -0
- package/dist/coordination/deploy-batcher.js +565 -0
- package/dist/coordination/deploy-batcher.js.map +1 -0
- package/dist/coordination/index.d.ts +5 -0
- package/dist/coordination/index.d.ts.map +1 -0
- package/dist/coordination/index.js +5 -0
- package/dist/coordination/index.js.map +1 -0
- package/dist/coordination/service.d.ts +81 -0
- package/dist/coordination/service.d.ts.map +1 -0
- package/dist/coordination/service.js +603 -0
- package/dist/coordination/service.js.map +1 -0
- package/dist/generators/claude-md.d.ts +3 -0
- package/dist/generators/claude-md.d.ts.map +1 -0
- package/dist/generators/claude-md.js +977 -0
- package/dist/generators/claude-md.js.map +1 -0
- package/dist/generators/template-loader.d.ts +105 -0
- package/dist/generators/template-loader.d.ts.map +1 -0
- package/dist/generators/template-loader.js +291 -0
- package/dist/generators/template-loader.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-router/config/parser.d.ts +9 -0
- package/dist/mcp-router/config/parser.d.ts.map +1 -0
- package/dist/mcp-router/config/parser.js +174 -0
- package/dist/mcp-router/config/parser.js.map +1 -0
- package/dist/mcp-router/executor/client.d.ts +31 -0
- package/dist/mcp-router/executor/client.d.ts.map +1 -0
- package/dist/mcp-router/executor/client.js +187 -0
- package/dist/mcp-router/executor/client.js.map +1 -0
- package/dist/mcp-router/index.d.ts +22 -0
- package/dist/mcp-router/index.d.ts.map +1 -0
- package/dist/mcp-router/index.js +18 -0
- package/dist/mcp-router/index.js.map +1 -0
- package/dist/mcp-router/output-compressor.d.ts +26 -0
- package/dist/mcp-router/output-compressor.d.ts.map +1 -0
- package/dist/mcp-router/output-compressor.js +236 -0
- package/dist/mcp-router/output-compressor.js.map +1 -0
- package/dist/mcp-router/search/fuzzy.d.ts +26 -0
- package/dist/mcp-router/search/fuzzy.d.ts.map +1 -0
- package/dist/mcp-router/search/fuzzy.js +94 -0
- package/dist/mcp-router/search/fuzzy.js.map +1 -0
- package/dist/mcp-router/server.d.ts +50 -0
- package/dist/mcp-router/server.d.ts.map +1 -0
- package/dist/mcp-router/server.js +229 -0
- package/dist/mcp-router/server.js.map +1 -0
- package/dist/mcp-router/session-stats.d.ts +37 -0
- package/dist/mcp-router/session-stats.d.ts.map +1 -0
- package/dist/mcp-router/session-stats.js +56 -0
- package/dist/mcp-router/session-stats.js.map +1 -0
- package/dist/mcp-router/tools/discover.d.ts +37 -0
- package/dist/mcp-router/tools/discover.d.ts.map +1 -0
- package/dist/mcp-router/tools/discover.js +65 -0
- package/dist/mcp-router/tools/discover.js.map +1 -0
- package/dist/mcp-router/tools/execute.d.ts +43 -0
- package/dist/mcp-router/tools/execute.d.ts.map +1 -0
- package/dist/mcp-router/tools/execute.js +103 -0
- package/dist/mcp-router/tools/execute.js.map +1 -0
- package/dist/mcp-router/types.d.ts +62 -0
- package/dist/mcp-router/types.d.ts.map +1 -0
- package/dist/mcp-router/types.js +6 -0
- package/dist/mcp-router/types.js.map +1 -0
- package/dist/memory/adaptive-context.d.ts +146 -0
- package/dist/memory/adaptive-context.d.ts.map +1 -0
- package/dist/memory/adaptive-context.js +1022 -0
- package/dist/memory/adaptive-context.js.map +1 -0
- package/dist/memory/agent-scoped-memory.d.ts +67 -0
- package/dist/memory/agent-scoped-memory.d.ts.map +1 -0
- package/dist/memory/agent-scoped-memory.js +126 -0
- package/dist/memory/agent-scoped-memory.js.map +1 -0
- package/dist/memory/backends/base.d.ts +18 -0
- package/dist/memory/backends/base.d.ts.map +1 -0
- package/dist/memory/backends/base.js +2 -0
- package/dist/memory/backends/base.js.map +1 -0
- package/dist/memory/backends/factory.d.ts +4 -0
- package/dist/memory/backends/factory.d.ts.map +1 -0
- package/dist/memory/backends/factory.js +53 -0
- package/dist/memory/backends/factory.js.map +1 -0
- package/dist/memory/backends/github.d.ts +22 -0
- package/dist/memory/backends/github.d.ts.map +1 -0
- package/dist/memory/backends/github.js +118 -0
- package/dist/memory/backends/github.js.map +1 -0
- package/dist/memory/backends/qdrant-cloud.d.ts +32 -0
- package/dist/memory/backends/qdrant-cloud.d.ts.map +1 -0
- package/dist/memory/backends/qdrant-cloud.js +168 -0
- package/dist/memory/backends/qdrant-cloud.js.map +1 -0
- package/dist/memory/context-compressor.d.ts +74 -0
- package/dist/memory/context-compressor.d.ts.map +1 -0
- package/dist/memory/context-compressor.js +289 -0
- package/dist/memory/context-compressor.js.map +1 -0
- package/dist/memory/correction-propagator.d.ts +44 -0
- package/dist/memory/correction-propagator.d.ts.map +1 -0
- package/dist/memory/correction-propagator.js +156 -0
- package/dist/memory/correction-propagator.js.map +1 -0
- package/dist/memory/daily-log.d.ts +67 -0
- package/dist/memory/daily-log.d.ts.map +1 -0
- package/dist/memory/daily-log.js +143 -0
- package/dist/memory/daily-log.js.map +1 -0
- package/dist/memory/dynamic-retrieval.d.ts +110 -0
- package/dist/memory/dynamic-retrieval.d.ts.map +1 -0
- package/dist/memory/dynamic-retrieval.js +688 -0
- package/dist/memory/dynamic-retrieval.js.map +1 -0
- package/dist/memory/embeddings.d.ts +116 -0
- package/dist/memory/embeddings.d.ts.map +1 -0
- package/dist/memory/embeddings.js +461 -0
- package/dist/memory/embeddings.js.map +1 -0
- package/dist/memory/hierarchical-memory.d.ts +141 -0
- package/dist/memory/hierarchical-memory.d.ts.map +1 -0
- package/dist/memory/hierarchical-memory.js +477 -0
- package/dist/memory/hierarchical-memory.js.map +1 -0
- package/dist/memory/memory-consolidator.d.ts +124 -0
- package/dist/memory/memory-consolidator.d.ts.map +1 -0
- package/dist/memory/memory-consolidator.js +514 -0
- package/dist/memory/memory-consolidator.js.map +1 -0
- package/dist/memory/memory-maintenance.d.ts +39 -0
- package/dist/memory/memory-maintenance.d.ts.map +1 -0
- package/dist/memory/memory-maintenance.js +305 -0
- package/dist/memory/memory-maintenance.js.map +1 -0
- package/dist/memory/model-router.d.ts +102 -0
- package/dist/memory/model-router.d.ts.map +1 -0
- package/dist/memory/model-router.js +448 -0
- package/dist/memory/model-router.js.map +1 -0
- package/dist/memory/multi-view-memory.d.ts +134 -0
- package/dist/memory/multi-view-memory.d.ts.map +1 -0
- package/dist/memory/multi-view-memory.js +420 -0
- package/dist/memory/multi-view-memory.js.map +1 -0
- package/dist/memory/prepopulate.d.ts +76 -0
- package/dist/memory/prepopulate.d.ts.map +1 -0
- package/dist/memory/prepopulate.js +815 -0
- package/dist/memory/prepopulate.js.map +1 -0
- package/dist/memory/semantic-compression.d.ts +77 -0
- package/dist/memory/semantic-compression.d.ts.map +1 -0
- package/dist/memory/semantic-compression.js +348 -0
- package/dist/memory/semantic-compression.js.map +1 -0
- package/dist/memory/serverless-qdrant.d.ts +102 -0
- package/dist/memory/serverless-qdrant.d.ts.map +1 -0
- package/dist/memory/serverless-qdrant.js +369 -0
- package/dist/memory/serverless-qdrant.js.map +1 -0
- package/dist/memory/short-term/factory.d.ts +26 -0
- package/dist/memory/short-term/factory.d.ts.map +1 -0
- package/dist/memory/short-term/factory.js +28 -0
- package/dist/memory/short-term/factory.js.map +1 -0
- package/dist/memory/short-term/indexeddb.d.ts +25 -0
- package/dist/memory/short-term/indexeddb.d.ts.map +1 -0
- package/dist/memory/short-term/indexeddb.js +64 -0
- package/dist/memory/short-term/indexeddb.js.map +1 -0
- package/dist/memory/short-term/schema.d.ts +6 -0
- package/dist/memory/short-term/schema.d.ts.map +1 -0
- package/dist/memory/short-term/schema.js +119 -0
- package/dist/memory/short-term/schema.js.map +1 -0
- package/dist/memory/short-term/sqlite.d.ts +50 -0
- package/dist/memory/short-term/sqlite.d.ts.map +1 -0
- package/dist/memory/short-term/sqlite.js +221 -0
- package/dist/memory/short-term/sqlite.js.map +1 -0
- package/dist/memory/speculative-cache.d.ts +111 -0
- package/dist/memory/speculative-cache.d.ts.map +1 -0
- package/dist/memory/speculative-cache.js +409 -0
- package/dist/memory/speculative-cache.js.map +1 -0
- package/dist/memory/task-classifier.d.ts +34 -0
- package/dist/memory/task-classifier.d.ts.map +1 -0
- package/dist/memory/task-classifier.js +300 -0
- package/dist/memory/task-classifier.js.map +1 -0
- package/dist/memory/terminal-bench-knowledge.d.ts +48 -0
- package/dist/memory/terminal-bench-knowledge.d.ts.map +1 -0
- package/dist/memory/terminal-bench-knowledge.js +399 -0
- package/dist/memory/terminal-bench-knowledge.js.map +1 -0
- package/dist/memory/write-gate.d.ts +39 -0
- package/dist/memory/write-gate.d.ts.map +1 -0
- package/dist/memory/write-gate.js +190 -0
- package/dist/memory/write-gate.js.map +1 -0
- package/dist/models/executor.d.ts +130 -0
- package/dist/models/executor.d.ts.map +1 -0
- package/dist/models/executor.js +383 -0
- package/dist/models/executor.js.map +1 -0
- package/dist/models/index.d.ts +15 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +17 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/planner.d.ts +71 -0
- package/dist/models/planner.d.ts.map +1 -0
- package/dist/models/planner.js +344 -0
- package/dist/models/planner.js.map +1 -0
- package/dist/models/router.d.ts +75 -0
- package/dist/models/router.d.ts.map +1 -0
- package/dist/models/router.js +344 -0
- package/dist/models/router.js.map +1 -0
- package/dist/models/types.d.ts +370 -0
- package/dist/models/types.d.ts.map +1 -0
- package/dist/models/types.js +181 -0
- package/dist/models/types.js.map +1 -0
- package/dist/tasks/coordination.d.ts +74 -0
- package/dist/tasks/coordination.d.ts.map +1 -0
- package/dist/tasks/coordination.js +237 -0
- package/dist/tasks/coordination.js.map +1 -0
- package/dist/tasks/database.d.ts +14 -0
- package/dist/tasks/database.d.ts.map +1 -0
- package/dist/tasks/database.js +128 -0
- package/dist/tasks/database.js.map +1 -0
- package/dist/tasks/index.d.ts +5 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +5 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/tasks/service.d.ts +39 -0
- package/dist/tasks/service.d.ts.map +1 -0
- package/dist/tasks/service.js +582 -0
- package/dist/tasks/service.js.map +1 -0
- package/dist/tasks/types.d.ts +224 -0
- package/dist/tasks/types.d.ts.map +1 -0
- package/dist/tasks/types.js +64 -0
- package/dist/tasks/types.js.map +1 -0
- package/dist/types/analysis.d.ts +82 -0
- package/dist/types/analysis.d.ts.map +1 -0
- package/dist/types/analysis.js +2 -0
- package/dist/types/analysis.js.map +1 -0
- package/dist/types/config.d.ts +3023 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +292 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/coordination.d.ts +240 -0
- package/dist/types/coordination.d.ts.map +1 -0
- package/dist/types/coordination.js +43 -0
- package/dist/types/coordination.js.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/calculate-average.d.ts +15 -0
- package/dist/utils/calculate-average.d.ts.map +1 -0
- package/dist/utils/calculate-average.js +21 -0
- package/dist/utils/calculate-average.js.map +1 -0
- package/dist/utils/config-manager.d.ts +30 -0
- package/dist/utils/config-manager.d.ts.map +1 -0
- package/dist/utils/config-manager.js +41 -0
- package/dist/utils/config-manager.js.map +1 -0
- package/dist/utils/dijkstra.d.ts +17 -0
- package/dist/utils/dijkstra.d.ts.map +1 -0
- package/dist/utils/dijkstra.js +91 -0
- package/dist/utils/dijkstra.js.map +1 -0
- package/dist/utils/fetch-with-retry.d.ts +5 -0
- package/dist/utils/fetch-with-retry.d.ts.map +1 -0
- package/dist/utils/fetch-with-retry.js +61 -0
- package/dist/utils/fetch-with-retry.js.map +1 -0
- package/dist/utils/merge-claude-md.d.ts +28 -0
- package/dist/utils/merge-claude-md.d.ts.map +1 -0
- package/dist/utils/merge-claude-md.js +342 -0
- package/dist/utils/merge-claude-md.js.map +1 -0
- package/dist/utils/order-processor-refactored.d.ts +126 -0
- package/dist/utils/order-processor-refactored.d.ts.map +1 -0
- package/dist/utils/order-processor-refactored.js +165 -0
- package/dist/utils/order-processor-refactored.js.map +1 -0
- package/dist/utils/order-processor-strategy.d.ts +72 -0
- package/dist/utils/order-processor-strategy.d.ts.map +1 -0
- package/dist/utils/order-processor-strategy.js +158 -0
- package/dist/utils/order-processor-strategy.js.map +1 -0
- package/dist/utils/order-processor.d.ts +242 -0
- package/dist/utils/order-processor.d.ts.map +1 -0
- package/dist/utils/order-processor.js +370 -0
- package/dist/utils/order-processor.js.map +1 -0
- package/dist/utils/rate-limiter-simple.d.ts +58 -0
- package/dist/utils/rate-limiter-simple.d.ts.map +1 -0
- package/dist/utils/rate-limiter-simple.js +100 -0
- package/dist/utils/rate-limiter-simple.js.map +1 -0
- package/dist/utils/rate-limiter.d.ts +62 -0
- package/dist/utils/rate-limiter.d.ts.map +1 -0
- package/dist/utils/rate-limiter.js +150 -0
- package/dist/utils/rate-limiter.js.map +1 -0
- package/dist/utils/string-similarity.d.ts +37 -0
- package/dist/utils/string-similarity.d.ts.map +1 -0
- package/dist/utils/string-similarity.js +114 -0
- package/dist/utils/string-similarity.js.map +1 -0
- package/dist/utils/validate-json.d.ts +51 -0
- package/dist/utils/validate-json.d.ts.map +1 -0
- package/dist/utils/validate-json.js +99 -0
- package/dist/utils/validate-json.js.map +1 -0
- package/package.json +96 -0
- package/templates/CLAUDE.template.md +11 -0
- package/templates/CLAUDE_ARCHITECTURE.template.md +103 -0
- package/templates/CLAUDE_CODING.template.md +125 -0
- package/templates/CLAUDE_DROIDS.template.md +109 -0
- package/templates/CLAUDE_MEMORY.template.md +130 -0
- package/templates/CLAUDE_WORKFLOWS.template.md +136 -0
- package/templates/PROJECT.template.md +209 -0
- package/templates/SCHEMA.md +57 -0
- package/templates/archive/CLAUDE.template.root-v6.md +762 -0
- package/templates/archive/CLAUDE.template.v6.md +762 -0
- package/templates/hooks/pre-compact.sh +68 -0
- package/templates/hooks/session-start.sh +106 -0
- package/tools/agents/README.md +224 -0
- package/tools/agents/UAP/README.md +351 -0
- package/tools/agents/UAP/__init__.py +9 -0
- package/tools/agents/UAP/cli.py +675 -0
- package/tools/agents/UAP/version.py +2 -0
- package/tools/agents/benchmarks/benchmark_memory_systems.py +637 -0
- package/tools/agents/benchmarks/results/benchmark_20260106_064817.json +170 -0
- package/tools/agents/benchmarks/results/benchmark_20260106_064817.md +51 -0
- package/tools/agents/config/chat_template.jinja +172 -0
- package/tools/agents/docker-compose.qdrant.yml +24 -0
- package/tools/agents/migrations/apply.py +256 -0
- package/tools/agents/scripts/fix_qwen_chat_template.py +314 -0
- package/tools/agents/scripts/init_qdrant.py +151 -0
- package/tools/agents/scripts/memory_migration.py +518 -0
- package/tools/agents/scripts/migrate_memory_to_qdrant.py +113 -0
- package/tools/agents/scripts/query_memory.py +189 -0
- package/tools/agents/scripts/qwen_tool_call_test.py +419 -0
- package/tools/agents/scripts/qwen_tool_call_wrapper.py +517 -0
- package/tools/agents/scripts/start-services.sh +96 -0
- package/tools/agents/tests/test_uap_compliance.py +257 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Qwen3.5 Chat Template Patch Script
|
|
4
|
+
|
|
5
|
+
Fixes the broken Jinja2 template that causes tool calling failures
|
|
6
|
+
after the first 1-2 tool calls.
|
|
7
|
+
|
|
8
|
+
Issue: Unclosed conditional blocks in tool call argument rendering
|
|
9
|
+
Source: Hugging Face Discussion #4
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
python3 fix_qwen_chat_template.py [template_file]
|
|
13
|
+
|
|
14
|
+
If no template file specified, looks for:
|
|
15
|
+
- chat_template.jinja
|
|
16
|
+
- .opencode/agent/chat_template.jinja
|
|
17
|
+
- llama.cpp templates
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import sys
|
|
21
|
+
import os
|
|
22
|
+
import re
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
from datetime import datetime
|
|
25
|
+
|
|
26
|
+
# Template fix patterns
|
|
27
|
+
FIXES = [
|
|
28
|
+
{
|
|
29
|
+
"name": "Add conditional wrapper for tool call arguments",
|
|
30
|
+
"pattern": r"{%- for args_name, args_value in tool_call\.arguments \| items %}",
|
|
31
|
+
"replacement": "{%- if tool_call.arguments is mapping %}\n {%- for args_name in tool_call.arguments %}",
|
|
32
|
+
"description": "Wraps tool call iteration in conditional to prevent errors",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "Add missing endif after tool call loop",
|
|
36
|
+
"pattern": r"(\{%- endfor %\}\s*)(?!\{%- endif %\})",
|
|
37
|
+
"replacement": r"\1{%- endif %}",
|
|
38
|
+
"description": "Closes the conditional block for tool call arguments",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"name": "Fix unclosed thinking tags",
|
|
42
|
+
"pattern": r"(<thinking>.*?)(?!</thinking>)\s*(?=<function|</function>)",
|
|
43
|
+
"replacement": r"\1</thinking>",
|
|
44
|
+
"description": "Ensures thinking tags are properly closed",
|
|
45
|
+
"flags": re.DOTALL,
|
|
46
|
+
},
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def find_template_files():
|
|
51
|
+
"""Search for Qwen3.5 chat template files"""
|
|
52
|
+
search_paths = [
|
|
53
|
+
Path("."),
|
|
54
|
+
Path(".opencode/agent"),
|
|
55
|
+
Path("llama.cpp"),
|
|
56
|
+
Path("tools/agents"),
|
|
57
|
+
Path("infra/k8s"),
|
|
58
|
+
Path("templates"),
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
template_files = []
|
|
62
|
+
|
|
63
|
+
for search_path in search_paths:
|
|
64
|
+
if not search_path.exists():
|
|
65
|
+
continue
|
|
66
|
+
|
|
67
|
+
# Look for template files
|
|
68
|
+
patterns = ["chat_template.jinja", "chat_template.txt", "qwen*.jinja"]
|
|
69
|
+
|
|
70
|
+
for pattern in patterns:
|
|
71
|
+
found = list(search_path.glob(pattern))
|
|
72
|
+
template_files.extend(found)
|
|
73
|
+
|
|
74
|
+
# Also check for files with Qwen in name
|
|
75
|
+
if (search_path / "tokenizer_config.json").exists():
|
|
76
|
+
template_files.append(search_path / "tokenizer_config.json")
|
|
77
|
+
|
|
78
|
+
# Remove duplicates and sort by path length (prefer more specific paths)
|
|
79
|
+
unique_files = list(set(template_files))
|
|
80
|
+
unique_files.sort(key=lambda x: len(str(x)))
|
|
81
|
+
|
|
82
|
+
return unique_files
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def read_template(filepath):
|
|
86
|
+
"""Read template file content"""
|
|
87
|
+
try:
|
|
88
|
+
with open(filepath, "r", encoding="utf-8") as f:
|
|
89
|
+
return f.read()
|
|
90
|
+
except Exception as e:
|
|
91
|
+
print(f"ā Error reading {filepath}: {e}")
|
|
92
|
+
return None
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def write_template(filepath, content):
|
|
96
|
+
"""Write content to template file"""
|
|
97
|
+
try:
|
|
98
|
+
with open(filepath, "w", encoding="utf-8") as f:
|
|
99
|
+
f.write(content)
|
|
100
|
+
return True
|
|
101
|
+
except Exception as e:
|
|
102
|
+
print(f"ā Error writing {filepath}: {e}")
|
|
103
|
+
return False
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def backup_template(filepath):
|
|
107
|
+
"""Create backup of template file"""
|
|
108
|
+
backup_path = f"{filepath}.backup.{datetime.now().strftime('%Y%m%d_%H%M%S')}"
|
|
109
|
+
|
|
110
|
+
try:
|
|
111
|
+
with open(filepath, "r", encoding="utf-8") as src:
|
|
112
|
+
with open(backup_path, "w", encoding="utf-8") as dst:
|
|
113
|
+
dst.write(src.read())
|
|
114
|
+
print(f"ā
Backup created: {backup_path}")
|
|
115
|
+
return backup_path
|
|
116
|
+
except Exception as e:
|
|
117
|
+
print(f"ā Error creating backup: {e}")
|
|
118
|
+
return None
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def apply_fix(template_content, fix):
|
|
122
|
+
"""Apply a single fix to template content"""
|
|
123
|
+
name = fix["name"]
|
|
124
|
+
pattern = fix["pattern"]
|
|
125
|
+
replacement = fix["replacement"]
|
|
126
|
+
flags = fix.get("flags", 0)
|
|
127
|
+
|
|
128
|
+
try:
|
|
129
|
+
# Check if pattern exists in template
|
|
130
|
+
if re.search(pattern, template_content, flags):
|
|
131
|
+
# Apply fix
|
|
132
|
+
new_content = re.sub(pattern, replacement, template_content, flags=flags)
|
|
133
|
+
|
|
134
|
+
# Check if fix was actually applied
|
|
135
|
+
if new_content != template_content:
|
|
136
|
+
print(f" ā Applied: {name}")
|
|
137
|
+
return new_content, True
|
|
138
|
+
else:
|
|
139
|
+
print(f" - Skipped: {name} (pattern not found)")
|
|
140
|
+
return template_content, False
|
|
141
|
+
else:
|
|
142
|
+
print(f" - Skipped: {name} (pattern not found)")
|
|
143
|
+
return template_content, False
|
|
144
|
+
|
|
145
|
+
except Exception as e:
|
|
146
|
+
print(f" ā Error applying {name}: {e}")
|
|
147
|
+
return template_content, False
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def validate_template(template_content):
|
|
151
|
+
"""Validate template structure"""
|
|
152
|
+
issues = []
|
|
153
|
+
|
|
154
|
+
# Check for balanced braces
|
|
155
|
+
if_template_count = template_content.count("{%- if ")
|
|
156
|
+
endif_count = template_content.count("{%- endif %}")
|
|
157
|
+
|
|
158
|
+
if if_template_count != endif_count:
|
|
159
|
+
issues.append(
|
|
160
|
+
f"Unbalanced if/endif: {if_template_count} if, {endif_count} endif"
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
# Check for tool call arguments pattern
|
|
164
|
+
if "tool_call.arguments" in template_content:
|
|
165
|
+
if "if tool_call.arguments is mapping" not in template_content:
|
|
166
|
+
issues.append("Missing conditional wrapper for tool_call.arguments")
|
|
167
|
+
|
|
168
|
+
# Check for thinking tags
|
|
169
|
+
thinking_open = template_content.count("<thinking>")
|
|
170
|
+
thinking_close = template_content.count("</thinking>")
|
|
171
|
+
|
|
172
|
+
if thinking_open != thinking_close:
|
|
173
|
+
issues.append(
|
|
174
|
+
f"Unbalanced thinking tags: {thinking_open} open, {thinking_close} close"
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
return issues
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def print_template_diff(old_content, new_content):
|
|
181
|
+
"""Print simplified diff showing key changes"""
|
|
182
|
+
old_lines = old_content.split("\n")
|
|
183
|
+
new_lines = new_content.split("\n")
|
|
184
|
+
|
|
185
|
+
print("\n" + "=" * 70)
|
|
186
|
+
print("KEY CHANGES:")
|
|
187
|
+
print("=" * 70)
|
|
188
|
+
|
|
189
|
+
# Find lines with tool call arguments
|
|
190
|
+
for i, line in enumerate(new_lines):
|
|
191
|
+
if "tool_call.arguments" in line and ("if" in line or "for" in line):
|
|
192
|
+
print(f"Line {i + 1}: {line.strip()}")
|
|
193
|
+
|
|
194
|
+
# Find endif additions
|
|
195
|
+
for i, line in enumerate(new_lines):
|
|
196
|
+
if "{%- endif %}" in line:
|
|
197
|
+
# Check if preceded by endfor
|
|
198
|
+
if i > 0 and "{%- endfor %}" in new_lines[i - 1]:
|
|
199
|
+
print(f"Line {i + 1}: {line.strip()} (closing tool call conditional)")
|
|
200
|
+
|
|
201
|
+
print("=" * 70 + "\n")
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def main():
|
|
205
|
+
"""Main execution"""
|
|
206
|
+
print("=" * 70)
|
|
207
|
+
print("Qwen3.5 Chat Template Patch Script")
|
|
208
|
+
print("=" * 70)
|
|
209
|
+
|
|
210
|
+
# Get template file
|
|
211
|
+
if len(sys.argv) > 1:
|
|
212
|
+
template_file = Path(sys.argv[1])
|
|
213
|
+
if not template_file.exists():
|
|
214
|
+
print(f"ā Template file not found: {template_file}")
|
|
215
|
+
sys.exit(1)
|
|
216
|
+
else:
|
|
217
|
+
print("Searching for template files...")
|
|
218
|
+
template_files = find_template_files()
|
|
219
|
+
|
|
220
|
+
if not template_files:
|
|
221
|
+
print("ā No template files found")
|
|
222
|
+
print("\nPlease specify template file manually:")
|
|
223
|
+
print(" python3 fix_qwen_chat_template.py /path/to/chat_template.jinja")
|
|
224
|
+
sys.exit(1)
|
|
225
|
+
|
|
226
|
+
print(f"Found {len(template_files)} potential template file(s):")
|
|
227
|
+
for i, tf in enumerate(template_files, 1):
|
|
228
|
+
print(f" {i}. {tf}")
|
|
229
|
+
|
|
230
|
+
# Use the most specific one (first in list)
|
|
231
|
+
template_file = template_files[0]
|
|
232
|
+
print(f"\nUsing: {template_file}\n")
|
|
233
|
+
|
|
234
|
+
# Read template
|
|
235
|
+
print(f"Reading template: {template_file}")
|
|
236
|
+
original_content = read_template(template_file)
|
|
237
|
+
|
|
238
|
+
if not original_content:
|
|
239
|
+
sys.exit(1)
|
|
240
|
+
|
|
241
|
+
# Create backup
|
|
242
|
+
backup_path = backup_template(template_file)
|
|
243
|
+
if not backup_path:
|
|
244
|
+
sys.exit(1)
|
|
245
|
+
|
|
246
|
+
# Validate before fix
|
|
247
|
+
print("\nValidating template before fix:")
|
|
248
|
+
issues_before = validate_template(original_content)
|
|
249
|
+
if issues_before:
|
|
250
|
+
print(" Issues found:")
|
|
251
|
+
for issue in issues_before:
|
|
252
|
+
print(f" - {issue}")
|
|
253
|
+
else:
|
|
254
|
+
print(" No obvious issues detected")
|
|
255
|
+
|
|
256
|
+
# Apply fixes
|
|
257
|
+
print("\nApplying fixes:")
|
|
258
|
+
fixed_content = original_content
|
|
259
|
+
|
|
260
|
+
for fix in FIXES:
|
|
261
|
+
fixed_content, applied = apply_fix(fixed_content, fix)
|
|
262
|
+
|
|
263
|
+
# Validate after fix
|
|
264
|
+
print("\nValidating template after fix:")
|
|
265
|
+
issues_after = validate_template(fixed_content)
|
|
266
|
+
if issues_after:
|
|
267
|
+
print(" Remaining issues:")
|
|
268
|
+
for issue in issues_after:
|
|
269
|
+
print(f" - {issue}")
|
|
270
|
+
else:
|
|
271
|
+
print(" ā No obvious issues detected")
|
|
272
|
+
|
|
273
|
+
# Write fixed template
|
|
274
|
+
if fixed_content != original_content:
|
|
275
|
+
print(f"\nWriting fixed template: {template_file}")
|
|
276
|
+
if write_template(template_file, fixed_content):
|
|
277
|
+
print("ā
Template patch applied successfully!")
|
|
278
|
+
else:
|
|
279
|
+
print("ā Failed to write template")
|
|
280
|
+
sys.exit(1)
|
|
281
|
+
else:
|
|
282
|
+
print("\nā ļø No changes were made - template may already be fixed")
|
|
283
|
+
|
|
284
|
+
# Print summary
|
|
285
|
+
print_template_diff(original_content, fixed_content)
|
|
286
|
+
|
|
287
|
+
# Print instructions
|
|
288
|
+
print("\n" + "=" * 70)
|
|
289
|
+
print("NEXT STEPS:")
|
|
290
|
+
print("=" * 70)
|
|
291
|
+
print("1. Verify the template was patched correctly:")
|
|
292
|
+
print(f" grep -n 'if tool_call.arguments is mapping' {template_file}")
|
|
293
|
+
print("\n2. Restart llama.cpp server with the fixed template:")
|
|
294
|
+
print(" ./llama.cpp/llama-server \\")
|
|
295
|
+
print(" --chat-template-file chat_template.jinja \\")
|
|
296
|
+
print(" --jinja \\")
|
|
297
|
+
print(" --port 8080")
|
|
298
|
+
print("\n3. Test tool calling:")
|
|
299
|
+
print(" python3 qwen_tool_call_test.py")
|
|
300
|
+
print("=" * 70)
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
if __name__ == "__main__":
|
|
304
|
+
try:
|
|
305
|
+
main()
|
|
306
|
+
except KeyboardInterrupt:
|
|
307
|
+
print("\nā Interrupted by user")
|
|
308
|
+
sys.exit(1)
|
|
309
|
+
except Exception as e:
|
|
310
|
+
print(f"\nā Unexpected error: {e}")
|
|
311
|
+
import traceback
|
|
312
|
+
|
|
313
|
+
traceback.print_exc()
|
|
314
|
+
sys.exit(1)
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Qdrant Vector Database Initialization Script
|
|
4
|
+
|
|
5
|
+
This script initializes the Qdrant collection for semantic memory.
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
tools/agents/scripts/init_qdrant.py
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
try:
|
|
15
|
+
from sentence_transformers import SentenceTransformer
|
|
16
|
+
from qdrant_client import QdrantClient
|
|
17
|
+
from qdrant_client.models import (
|
|
18
|
+
Distance,
|
|
19
|
+
VectorParams,
|
|
20
|
+
PointStruct,
|
|
21
|
+
)
|
|
22
|
+
except ImportError:
|
|
23
|
+
print("ā Required packages not installed")
|
|
24
|
+
print("\nInstall with:")
|
|
25
|
+
print(" tools/agents/.venv/bin/pip install sentence-transformers qdrant-client")
|
|
26
|
+
sys.exit(1)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get_project_root():
|
|
30
|
+
"""Get project root directory."""
|
|
31
|
+
return Path(__file__).parent.parent.parent
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def init_collection():
|
|
35
|
+
"""Initialize Qdrant collection for UAM memory."""
|
|
36
|
+
print("=== Initializing Qdrant Vector Database ===\n")
|
|
37
|
+
|
|
38
|
+
# Connect to Qdrant
|
|
39
|
+
client = QdrantClient(host="localhost", port=6333)
|
|
40
|
+
|
|
41
|
+
# Check if collection exists
|
|
42
|
+
collections = client.get_collections().collections
|
|
43
|
+
collection_name = "uam_memory"
|
|
44
|
+
|
|
45
|
+
if any(c.name == collection_name for c in collections):
|
|
46
|
+
print(f"ā ļø Collection '{collection_name}' already exists")
|
|
47
|
+
response = input("Delete and recreate? (y/N): ").strip().lower()
|
|
48
|
+
if response != "y":
|
|
49
|
+
print("Skipping initialization")
|
|
50
|
+
return 0
|
|
51
|
+
|
|
52
|
+
# Load embedding model
|
|
53
|
+
print("š¦ Loading embedding model (this may take a minute)...")
|
|
54
|
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
|
55
|
+
vector_size = len(model.encode("test"))
|
|
56
|
+
print(f" ā
Model loaded, vector size: {vector_size}")
|
|
57
|
+
|
|
58
|
+
# Create collection
|
|
59
|
+
print(f"\nš¦ Creating collection '{collection_name}'...")
|
|
60
|
+
client.create_collection(
|
|
61
|
+
collection_name=collection_name,
|
|
62
|
+
vectors=VectorParams(size=vector_size, distance=Distance.COSINE),
|
|
63
|
+
)
|
|
64
|
+
print(" ā
Collection created")
|
|
65
|
+
|
|
66
|
+
# Create payload index for metadata filtering
|
|
67
|
+
print("\nš¦ Creating payload indexes...")
|
|
68
|
+
client.create_payload_index(
|
|
69
|
+
collection_name=collection_name,
|
|
70
|
+
field_name="type",
|
|
71
|
+
field_schema="keyword",
|
|
72
|
+
)
|
|
73
|
+
client.create_payload_index(
|
|
74
|
+
collection_name=collection_name,
|
|
75
|
+
field_name="tags",
|
|
76
|
+
field_schema="keyword",
|
|
77
|
+
)
|
|
78
|
+
client.create_payload_index(
|
|
79
|
+
collection_name=collection_name,
|
|
80
|
+
field_name="importance",
|
|
81
|
+
field_schema="integer",
|
|
82
|
+
)
|
|
83
|
+
print(" ā
Payload indexes created")
|
|
84
|
+
|
|
85
|
+
# Migrate existing JSON memories
|
|
86
|
+
json_memory_path = get_project_root() / "agents/data/memory/long_term.json"
|
|
87
|
+
if json_memory_path.exists():
|
|
88
|
+
print(f"\nš¦ Migrating memories from {json_memory_path}...")
|
|
89
|
+
|
|
90
|
+
import json
|
|
91
|
+
|
|
92
|
+
with open(json_memory_path, "r") as f:
|
|
93
|
+
data = json.load(f)
|
|
94
|
+
|
|
95
|
+
memories = data.get("memories", [])
|
|
96
|
+
points = []
|
|
97
|
+
|
|
98
|
+
for mem in memories:
|
|
99
|
+
embedding = model.encode(mem["content"]).tolist()
|
|
100
|
+
|
|
101
|
+
point = PointStruct(
|
|
102
|
+
id=mem.get("id", hash(mem["content"]) % 1000000),
|
|
103
|
+
vector=embedding,
|
|
104
|
+
payload={
|
|
105
|
+
"original_id": mem.get("id"),
|
|
106
|
+
"type": mem.get("type"),
|
|
107
|
+
"tags": mem.get("tags", []),
|
|
108
|
+
"importance": mem.get("importance", 5),
|
|
109
|
+
"content": mem.get("content"),
|
|
110
|
+
"timestamp": mem.get("timestamp"),
|
|
111
|
+
},
|
|
112
|
+
)
|
|
113
|
+
points.append(point)
|
|
114
|
+
|
|
115
|
+
if points:
|
|
116
|
+
client.upsert(collection_name=collection_name, points=points)
|
|
117
|
+
print(f" ā
Migrated {len(points)} memories")
|
|
118
|
+
else:
|
|
119
|
+
print(" ā ļø No memories to migrate")
|
|
120
|
+
else:
|
|
121
|
+
print("\nā ļø No long_term.json found (skipping migration)")
|
|
122
|
+
|
|
123
|
+
# Test query
|
|
124
|
+
print("\nš¦ Testing collection...")
|
|
125
|
+
test_query = "architecture"
|
|
126
|
+
test_embedding = model.encode(test_query).tolist()
|
|
127
|
+
|
|
128
|
+
results = client.search(
|
|
129
|
+
collection_name=collection_name,
|
|
130
|
+
query_vector=test_embedding,
|
|
131
|
+
limit=3,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
print(f" ā
Query successful: {len(results)} results found")
|
|
135
|
+
|
|
136
|
+
print("\n" + "=" * 50)
|
|
137
|
+
print("ā
Qdrant initialization completed!")
|
|
138
|
+
print("=" * 50)
|
|
139
|
+
print("\nCollection details:")
|
|
140
|
+
print(f" Name: {collection_name}")
|
|
141
|
+
print(f" Vector size: {vector_size}")
|
|
142
|
+
print(f" Distance: COSINE")
|
|
143
|
+
print(f" REST API: http://localhost:6333")
|
|
144
|
+
print(f"\nTo query:")
|
|
145
|
+
print(' tools/agents/scripts/query_memory.py long "<query>"')
|
|
146
|
+
|
|
147
|
+
return 0
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
if __name__ == "__main__":
|
|
151
|
+
sys.exit(init_collection())
|