PraisonAI 3.0.0__py3-none-any.whl
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.
- praisonai/__init__.py +54 -0
- praisonai/__main__.py +15 -0
- praisonai/acp/__init__.py +54 -0
- praisonai/acp/config.py +159 -0
- praisonai/acp/server.py +587 -0
- praisonai/acp/session.py +219 -0
- praisonai/adapters/__init__.py +50 -0
- praisonai/adapters/readers.py +395 -0
- praisonai/adapters/rerankers.py +315 -0
- praisonai/adapters/retrievers.py +394 -0
- praisonai/adapters/vector_stores.py +409 -0
- praisonai/agent_scheduler.py +337 -0
- praisonai/agents_generator.py +903 -0
- praisonai/api/call.py +292 -0
- praisonai/auto.py +1197 -0
- praisonai/capabilities/__init__.py +275 -0
- praisonai/capabilities/a2a.py +140 -0
- praisonai/capabilities/assistants.py +283 -0
- praisonai/capabilities/audio.py +320 -0
- praisonai/capabilities/batches.py +469 -0
- praisonai/capabilities/completions.py +336 -0
- praisonai/capabilities/container_files.py +155 -0
- praisonai/capabilities/containers.py +93 -0
- praisonai/capabilities/embeddings.py +158 -0
- praisonai/capabilities/files.py +467 -0
- praisonai/capabilities/fine_tuning.py +293 -0
- praisonai/capabilities/guardrails.py +182 -0
- praisonai/capabilities/images.py +330 -0
- praisonai/capabilities/mcp.py +190 -0
- praisonai/capabilities/messages.py +270 -0
- praisonai/capabilities/moderations.py +154 -0
- praisonai/capabilities/ocr.py +217 -0
- praisonai/capabilities/passthrough.py +204 -0
- praisonai/capabilities/rag.py +207 -0
- praisonai/capabilities/realtime.py +160 -0
- praisonai/capabilities/rerank.py +165 -0
- praisonai/capabilities/responses.py +266 -0
- praisonai/capabilities/search.py +109 -0
- praisonai/capabilities/skills.py +133 -0
- praisonai/capabilities/vector_store_files.py +334 -0
- praisonai/capabilities/vector_stores.py +304 -0
- praisonai/capabilities/videos.py +141 -0
- praisonai/chainlit_ui.py +304 -0
- praisonai/chat/__init__.py +106 -0
- praisonai/chat/app.py +125 -0
- praisonai/cli/__init__.py +26 -0
- praisonai/cli/app.py +213 -0
- praisonai/cli/commands/__init__.py +75 -0
- praisonai/cli/commands/acp.py +70 -0
- praisonai/cli/commands/completion.py +333 -0
- praisonai/cli/commands/config.py +166 -0
- praisonai/cli/commands/debug.py +142 -0
- praisonai/cli/commands/diag.py +55 -0
- praisonai/cli/commands/doctor.py +166 -0
- praisonai/cli/commands/environment.py +179 -0
- praisonai/cli/commands/lsp.py +112 -0
- praisonai/cli/commands/mcp.py +210 -0
- praisonai/cli/commands/profile.py +457 -0
- praisonai/cli/commands/run.py +228 -0
- praisonai/cli/commands/schedule.py +150 -0
- praisonai/cli/commands/serve.py +97 -0
- praisonai/cli/commands/session.py +212 -0
- praisonai/cli/commands/traces.py +145 -0
- praisonai/cli/commands/version.py +101 -0
- praisonai/cli/configuration/__init__.py +18 -0
- praisonai/cli/configuration/loader.py +353 -0
- praisonai/cli/configuration/paths.py +114 -0
- praisonai/cli/configuration/schema.py +164 -0
- praisonai/cli/features/__init__.py +268 -0
- praisonai/cli/features/acp.py +236 -0
- praisonai/cli/features/action_orchestrator.py +546 -0
- praisonai/cli/features/agent_scheduler.py +773 -0
- praisonai/cli/features/agent_tools.py +474 -0
- praisonai/cli/features/agents.py +375 -0
- praisonai/cli/features/at_mentions.py +471 -0
- praisonai/cli/features/auto_memory.py +182 -0
- praisonai/cli/features/autonomy_mode.py +490 -0
- praisonai/cli/features/background.py +356 -0
- praisonai/cli/features/base.py +168 -0
- praisonai/cli/features/capabilities.py +1326 -0
- praisonai/cli/features/checkpoints.py +338 -0
- praisonai/cli/features/code_intelligence.py +652 -0
- praisonai/cli/features/compaction.py +294 -0
- praisonai/cli/features/compare.py +534 -0
- praisonai/cli/features/cost_tracker.py +514 -0
- praisonai/cli/features/debug.py +810 -0
- praisonai/cli/features/deploy.py +517 -0
- praisonai/cli/features/diag.py +289 -0
- praisonai/cli/features/doctor/__init__.py +63 -0
- praisonai/cli/features/doctor/checks/__init__.py +24 -0
- praisonai/cli/features/doctor/checks/acp_checks.py +240 -0
- praisonai/cli/features/doctor/checks/config_checks.py +366 -0
- praisonai/cli/features/doctor/checks/db_checks.py +366 -0
- praisonai/cli/features/doctor/checks/env_checks.py +543 -0
- praisonai/cli/features/doctor/checks/lsp_checks.py +199 -0
- praisonai/cli/features/doctor/checks/mcp_checks.py +349 -0
- praisonai/cli/features/doctor/checks/memory_checks.py +268 -0
- praisonai/cli/features/doctor/checks/network_checks.py +251 -0
- praisonai/cli/features/doctor/checks/obs_checks.py +328 -0
- praisonai/cli/features/doctor/checks/performance_checks.py +235 -0
- praisonai/cli/features/doctor/checks/permissions_checks.py +259 -0
- praisonai/cli/features/doctor/checks/selftest_checks.py +322 -0
- praisonai/cli/features/doctor/checks/serve_checks.py +426 -0
- praisonai/cli/features/doctor/checks/skills_checks.py +231 -0
- praisonai/cli/features/doctor/checks/tools_checks.py +371 -0
- praisonai/cli/features/doctor/engine.py +266 -0
- praisonai/cli/features/doctor/formatters.py +310 -0
- praisonai/cli/features/doctor/handler.py +397 -0
- praisonai/cli/features/doctor/models.py +264 -0
- praisonai/cli/features/doctor/registry.py +239 -0
- praisonai/cli/features/endpoints.py +1019 -0
- praisonai/cli/features/eval.py +560 -0
- praisonai/cli/features/external_agents.py +231 -0
- praisonai/cli/features/fast_context.py +410 -0
- praisonai/cli/features/flow_display.py +566 -0
- praisonai/cli/features/git_integration.py +651 -0
- praisonai/cli/features/guardrail.py +171 -0
- praisonai/cli/features/handoff.py +185 -0
- praisonai/cli/features/hooks.py +583 -0
- praisonai/cli/features/image.py +384 -0
- praisonai/cli/features/interactive_runtime.py +585 -0
- praisonai/cli/features/interactive_tools.py +380 -0
- praisonai/cli/features/interactive_tui.py +603 -0
- praisonai/cli/features/jobs.py +632 -0
- praisonai/cli/features/knowledge.py +531 -0
- praisonai/cli/features/lite.py +244 -0
- praisonai/cli/features/lsp_cli.py +225 -0
- praisonai/cli/features/mcp.py +169 -0
- praisonai/cli/features/message_queue.py +587 -0
- praisonai/cli/features/metrics.py +211 -0
- praisonai/cli/features/n8n.py +673 -0
- praisonai/cli/features/observability.py +293 -0
- praisonai/cli/features/ollama.py +361 -0
- praisonai/cli/features/output_style.py +273 -0
- praisonai/cli/features/package.py +631 -0
- praisonai/cli/features/performance.py +308 -0
- praisonai/cli/features/persistence.py +636 -0
- praisonai/cli/features/profile.py +226 -0
- praisonai/cli/features/profiler/__init__.py +81 -0
- praisonai/cli/features/profiler/core.py +558 -0
- praisonai/cli/features/profiler/optimizations.py +652 -0
- praisonai/cli/features/profiler/suite.py +386 -0
- praisonai/cli/features/profiling.py +350 -0
- praisonai/cli/features/queue/__init__.py +73 -0
- praisonai/cli/features/queue/manager.py +395 -0
- praisonai/cli/features/queue/models.py +286 -0
- praisonai/cli/features/queue/persistence.py +564 -0
- praisonai/cli/features/queue/scheduler.py +484 -0
- praisonai/cli/features/queue/worker.py +372 -0
- praisonai/cli/features/recipe.py +1723 -0
- praisonai/cli/features/recipes.py +449 -0
- praisonai/cli/features/registry.py +229 -0
- praisonai/cli/features/repo_map.py +860 -0
- praisonai/cli/features/router.py +466 -0
- praisonai/cli/features/sandbox_executor.py +515 -0
- praisonai/cli/features/serve.py +829 -0
- praisonai/cli/features/session.py +222 -0
- praisonai/cli/features/skills.py +856 -0
- praisonai/cli/features/slash_commands.py +650 -0
- praisonai/cli/features/telemetry.py +179 -0
- praisonai/cli/features/templates.py +1384 -0
- praisonai/cli/features/thinking.py +305 -0
- praisonai/cli/features/todo.py +334 -0
- praisonai/cli/features/tools.py +680 -0
- praisonai/cli/features/tui/__init__.py +83 -0
- praisonai/cli/features/tui/app.py +580 -0
- praisonai/cli/features/tui/cli.py +566 -0
- praisonai/cli/features/tui/debug.py +511 -0
- praisonai/cli/features/tui/events.py +99 -0
- praisonai/cli/features/tui/mock_provider.py +328 -0
- praisonai/cli/features/tui/orchestrator.py +652 -0
- praisonai/cli/features/tui/screens/__init__.py +50 -0
- praisonai/cli/features/tui/screens/main.py +245 -0
- praisonai/cli/features/tui/screens/queue.py +174 -0
- praisonai/cli/features/tui/screens/session.py +124 -0
- praisonai/cli/features/tui/screens/settings.py +148 -0
- praisonai/cli/features/tui/widgets/__init__.py +56 -0
- praisonai/cli/features/tui/widgets/chat.py +261 -0
- praisonai/cli/features/tui/widgets/composer.py +224 -0
- praisonai/cli/features/tui/widgets/queue_panel.py +200 -0
- praisonai/cli/features/tui/widgets/status.py +167 -0
- praisonai/cli/features/tui/widgets/tool_panel.py +248 -0
- praisonai/cli/features/workflow.py +720 -0
- praisonai/cli/legacy.py +236 -0
- praisonai/cli/main.py +5559 -0
- praisonai/cli/schedule_cli.py +54 -0
- praisonai/cli/state/__init__.py +31 -0
- praisonai/cli/state/identifiers.py +161 -0
- praisonai/cli/state/sessions.py +313 -0
- praisonai/code/__init__.py +93 -0
- praisonai/code/agent_tools.py +344 -0
- praisonai/code/diff/__init__.py +21 -0
- praisonai/code/diff/diff_strategy.py +432 -0
- praisonai/code/tools/__init__.py +27 -0
- praisonai/code/tools/apply_diff.py +221 -0
- praisonai/code/tools/execute_command.py +275 -0
- praisonai/code/tools/list_files.py +274 -0
- praisonai/code/tools/read_file.py +206 -0
- praisonai/code/tools/search_replace.py +248 -0
- praisonai/code/tools/write_file.py +217 -0
- praisonai/code/utils/__init__.py +46 -0
- praisonai/code/utils/file_utils.py +307 -0
- praisonai/code/utils/ignore_utils.py +308 -0
- praisonai/code/utils/text_utils.py +276 -0
- praisonai/db/__init__.py +64 -0
- praisonai/db/adapter.py +531 -0
- praisonai/deploy/__init__.py +62 -0
- praisonai/deploy/api.py +231 -0
- praisonai/deploy/docker.py +454 -0
- praisonai/deploy/doctor.py +367 -0
- praisonai/deploy/main.py +327 -0
- praisonai/deploy/models.py +179 -0
- praisonai/deploy/providers/__init__.py +33 -0
- praisonai/deploy/providers/aws.py +331 -0
- praisonai/deploy/providers/azure.py +358 -0
- praisonai/deploy/providers/base.py +101 -0
- praisonai/deploy/providers/gcp.py +314 -0
- praisonai/deploy/schema.py +208 -0
- praisonai/deploy.py +185 -0
- praisonai/endpoints/__init__.py +53 -0
- praisonai/endpoints/a2u_server.py +410 -0
- praisonai/endpoints/discovery.py +165 -0
- praisonai/endpoints/providers/__init__.py +28 -0
- praisonai/endpoints/providers/a2a.py +253 -0
- praisonai/endpoints/providers/a2u.py +208 -0
- praisonai/endpoints/providers/agents_api.py +171 -0
- praisonai/endpoints/providers/base.py +231 -0
- praisonai/endpoints/providers/mcp.py +263 -0
- praisonai/endpoints/providers/recipe.py +206 -0
- praisonai/endpoints/providers/tools_mcp.py +150 -0
- praisonai/endpoints/registry.py +131 -0
- praisonai/endpoints/server.py +161 -0
- praisonai/inbuilt_tools/__init__.py +24 -0
- praisonai/inbuilt_tools/autogen_tools.py +117 -0
- praisonai/inc/__init__.py +2 -0
- praisonai/inc/config.py +96 -0
- praisonai/inc/models.py +155 -0
- praisonai/integrations/__init__.py +56 -0
- praisonai/integrations/base.py +303 -0
- praisonai/integrations/claude_code.py +270 -0
- praisonai/integrations/codex_cli.py +255 -0
- praisonai/integrations/cursor_cli.py +195 -0
- praisonai/integrations/gemini_cli.py +222 -0
- praisonai/jobs/__init__.py +67 -0
- praisonai/jobs/executor.py +425 -0
- praisonai/jobs/models.py +230 -0
- praisonai/jobs/router.py +314 -0
- praisonai/jobs/server.py +186 -0
- praisonai/jobs/store.py +203 -0
- praisonai/llm/__init__.py +66 -0
- praisonai/llm/registry.py +382 -0
- praisonai/mcp_server/__init__.py +152 -0
- praisonai/mcp_server/adapters/__init__.py +74 -0
- praisonai/mcp_server/adapters/agents.py +128 -0
- praisonai/mcp_server/adapters/capabilities.py +168 -0
- praisonai/mcp_server/adapters/cli_tools.py +568 -0
- praisonai/mcp_server/adapters/extended_capabilities.py +462 -0
- praisonai/mcp_server/adapters/knowledge.py +93 -0
- praisonai/mcp_server/adapters/memory.py +104 -0
- praisonai/mcp_server/adapters/prompts.py +306 -0
- praisonai/mcp_server/adapters/resources.py +124 -0
- praisonai/mcp_server/adapters/tools_bridge.py +280 -0
- praisonai/mcp_server/auth/__init__.py +48 -0
- praisonai/mcp_server/auth/api_key.py +291 -0
- praisonai/mcp_server/auth/oauth.py +460 -0
- praisonai/mcp_server/auth/oidc.py +289 -0
- praisonai/mcp_server/auth/scopes.py +260 -0
- praisonai/mcp_server/cli.py +852 -0
- praisonai/mcp_server/elicitation.py +445 -0
- praisonai/mcp_server/icons.py +302 -0
- praisonai/mcp_server/recipe_adapter.py +573 -0
- praisonai/mcp_server/recipe_cli.py +824 -0
- praisonai/mcp_server/registry.py +703 -0
- praisonai/mcp_server/sampling.py +422 -0
- praisonai/mcp_server/server.py +490 -0
- praisonai/mcp_server/tasks.py +443 -0
- praisonai/mcp_server/transports/__init__.py +18 -0
- praisonai/mcp_server/transports/http_stream.py +376 -0
- praisonai/mcp_server/transports/stdio.py +132 -0
- praisonai/persistence/__init__.py +84 -0
- praisonai/persistence/config.py +238 -0
- praisonai/persistence/conversation/__init__.py +25 -0
- praisonai/persistence/conversation/async_mysql.py +427 -0
- praisonai/persistence/conversation/async_postgres.py +410 -0
- praisonai/persistence/conversation/async_sqlite.py +371 -0
- praisonai/persistence/conversation/base.py +151 -0
- praisonai/persistence/conversation/json_store.py +250 -0
- praisonai/persistence/conversation/mysql.py +387 -0
- praisonai/persistence/conversation/postgres.py +401 -0
- praisonai/persistence/conversation/singlestore.py +240 -0
- praisonai/persistence/conversation/sqlite.py +341 -0
- praisonai/persistence/conversation/supabase.py +203 -0
- praisonai/persistence/conversation/surrealdb.py +287 -0
- praisonai/persistence/factory.py +301 -0
- praisonai/persistence/hooks/__init__.py +18 -0
- praisonai/persistence/hooks/agent_hooks.py +297 -0
- praisonai/persistence/knowledge/__init__.py +26 -0
- praisonai/persistence/knowledge/base.py +144 -0
- praisonai/persistence/knowledge/cassandra.py +232 -0
- praisonai/persistence/knowledge/chroma.py +295 -0
- praisonai/persistence/knowledge/clickhouse.py +242 -0
- praisonai/persistence/knowledge/cosmosdb_vector.py +438 -0
- praisonai/persistence/knowledge/couchbase.py +286 -0
- praisonai/persistence/knowledge/lancedb.py +216 -0
- praisonai/persistence/knowledge/langchain_adapter.py +291 -0
- praisonai/persistence/knowledge/lightrag_adapter.py +212 -0
- praisonai/persistence/knowledge/llamaindex_adapter.py +256 -0
- praisonai/persistence/knowledge/milvus.py +277 -0
- praisonai/persistence/knowledge/mongodb_vector.py +306 -0
- praisonai/persistence/knowledge/pgvector.py +335 -0
- praisonai/persistence/knowledge/pinecone.py +253 -0
- praisonai/persistence/knowledge/qdrant.py +301 -0
- praisonai/persistence/knowledge/redis_vector.py +291 -0
- praisonai/persistence/knowledge/singlestore_vector.py +299 -0
- praisonai/persistence/knowledge/surrealdb_vector.py +309 -0
- praisonai/persistence/knowledge/upstash_vector.py +266 -0
- praisonai/persistence/knowledge/weaviate.py +223 -0
- praisonai/persistence/migrations/__init__.py +10 -0
- praisonai/persistence/migrations/manager.py +251 -0
- praisonai/persistence/orchestrator.py +406 -0
- praisonai/persistence/state/__init__.py +21 -0
- praisonai/persistence/state/async_mongodb.py +200 -0
- praisonai/persistence/state/base.py +107 -0
- praisonai/persistence/state/dynamodb.py +226 -0
- praisonai/persistence/state/firestore.py +175 -0
- praisonai/persistence/state/gcs.py +155 -0
- praisonai/persistence/state/memory.py +245 -0
- praisonai/persistence/state/mongodb.py +158 -0
- praisonai/persistence/state/redis.py +190 -0
- praisonai/persistence/state/upstash.py +144 -0
- praisonai/persistence/tests/__init__.py +3 -0
- praisonai/persistence/tests/test_all_backends.py +633 -0
- praisonai/profiler.py +1214 -0
- praisonai/recipe/__init__.py +134 -0
- praisonai/recipe/bridge.py +278 -0
- praisonai/recipe/core.py +893 -0
- praisonai/recipe/exceptions.py +54 -0
- praisonai/recipe/history.py +402 -0
- praisonai/recipe/models.py +266 -0
- praisonai/recipe/operations.py +440 -0
- praisonai/recipe/policy.py +422 -0
- praisonai/recipe/registry.py +849 -0
- praisonai/recipe/runtime.py +214 -0
- praisonai/recipe/security.py +711 -0
- praisonai/recipe/serve.py +859 -0
- praisonai/recipe/server.py +613 -0
- praisonai/scheduler/__init__.py +45 -0
- praisonai/scheduler/agent_scheduler.py +552 -0
- praisonai/scheduler/base.py +124 -0
- praisonai/scheduler/daemon_manager.py +225 -0
- praisonai/scheduler/state_manager.py +155 -0
- praisonai/scheduler/yaml_loader.py +193 -0
- praisonai/scheduler.py +194 -0
- praisonai/setup/__init__.py +1 -0
- praisonai/setup/build.py +21 -0
- praisonai/setup/post_install.py +23 -0
- praisonai/setup/setup_conda_env.py +25 -0
- praisonai/setup.py +16 -0
- praisonai/templates/__init__.py +116 -0
- praisonai/templates/cache.py +364 -0
- praisonai/templates/dependency_checker.py +358 -0
- praisonai/templates/discovery.py +391 -0
- praisonai/templates/loader.py +564 -0
- praisonai/templates/registry.py +511 -0
- praisonai/templates/resolver.py +206 -0
- praisonai/templates/security.py +327 -0
- praisonai/templates/tool_override.py +498 -0
- praisonai/templates/tools_doctor.py +256 -0
- praisonai/test.py +105 -0
- praisonai/train.py +562 -0
- praisonai/train_vision.py +306 -0
- praisonai/ui/agents.py +824 -0
- praisonai/ui/callbacks.py +57 -0
- praisonai/ui/chainlit_compat.py +246 -0
- praisonai/ui/chat.py +532 -0
- praisonai/ui/code.py +717 -0
- praisonai/ui/colab.py +474 -0
- praisonai/ui/colab_chainlit.py +81 -0
- praisonai/ui/components/aicoder.py +284 -0
- praisonai/ui/context.py +283 -0
- praisonai/ui/database_config.py +56 -0
- praisonai/ui/db.py +294 -0
- praisonai/ui/realtime.py +488 -0
- praisonai/ui/realtimeclient/__init__.py +756 -0
- praisonai/ui/realtimeclient/tools.py +242 -0
- praisonai/ui/sql_alchemy.py +710 -0
- praisonai/upload_vision.py +140 -0
- praisonai/version.py +1 -0
- praisonai-3.0.0.dist-info/METADATA +3493 -0
- praisonai-3.0.0.dist-info/RECORD +393 -0
- praisonai-3.0.0.dist-info/WHEEL +5 -0
- praisonai-3.0.0.dist-info/entry_points.txt +4 -0
- praisonai-3.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Lite Agent Handler for CLI.
|
|
3
|
+
|
|
4
|
+
Provides access to the lightweight praisonaiagents.lite subpackage.
|
|
5
|
+
Usage: praisonai lite [run|info]
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
from typing import Any, Dict, Tuple
|
|
10
|
+
from .base import FlagHandler
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class LiteHandler(FlagHandler):
|
|
14
|
+
"""
|
|
15
|
+
Handler for lite agent commands.
|
|
16
|
+
|
|
17
|
+
The lite subpackage provides a minimal agent framework without heavy
|
|
18
|
+
dependencies like litellm. Users can bring their own LLM client.
|
|
19
|
+
|
|
20
|
+
Commands:
|
|
21
|
+
praisonai lite run "prompt" - Run a lite agent with custom LLM
|
|
22
|
+
praisonai lite info - Show lite package info
|
|
23
|
+
praisonai lite example - Show example usage
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def feature_name(self) -> str:
|
|
28
|
+
return "lite"
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def flag_name(self) -> str:
|
|
32
|
+
return "lite"
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def flag_help(self) -> str:
|
|
36
|
+
return "Use lightweight agent without heavy dependencies"
|
|
37
|
+
|
|
38
|
+
def check_dependencies(self) -> Tuple[bool, str]:
|
|
39
|
+
"""Check if lite package is available."""
|
|
40
|
+
import importlib.util
|
|
41
|
+
if importlib.util.find_spec("praisonaiagents.lite") is not None:
|
|
42
|
+
return True, ""
|
|
43
|
+
return False, "Lite package requires praisonaiagents>=0.5.0"
|
|
44
|
+
|
|
45
|
+
def get_info(self) -> Dict[str, Any]:
|
|
46
|
+
"""
|
|
47
|
+
Get information about the lite package.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
Dict with package info
|
|
51
|
+
"""
|
|
52
|
+
import importlib.util
|
|
53
|
+
if importlib.util.find_spec("praisonaiagents.lite") is None:
|
|
54
|
+
return {
|
|
55
|
+
"available": False,
|
|
56
|
+
"error": "praisonaiagents.lite not found"
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
"available": True,
|
|
61
|
+
"classes": ["LiteAgent", "LiteTask", "LiteToolResult"],
|
|
62
|
+
"decorators": ["@tool"],
|
|
63
|
+
"helpers": ["create_openai_llm_fn", "create_anthropic_llm_fn"],
|
|
64
|
+
"features": [
|
|
65
|
+
"BYO-LLM (Bring Your Own LLM)",
|
|
66
|
+
"Thread-safe chat history",
|
|
67
|
+
"Tool execution",
|
|
68
|
+
"No litellm dependency",
|
|
69
|
+
"Minimal memory footprint"
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
def show_example(self) -> str:
|
|
74
|
+
"""
|
|
75
|
+
Show example usage of lite package.
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
Example code string
|
|
79
|
+
"""
|
|
80
|
+
example = '''
|
|
81
|
+
# Example: Using praisonaiagents.lite with custom LLM
|
|
82
|
+
|
|
83
|
+
from praisonaiagents.lite import LiteAgent, tool
|
|
84
|
+
|
|
85
|
+
# Define a custom LLM function
|
|
86
|
+
def my_llm(messages):
|
|
87
|
+
"""Your custom LLM implementation."""
|
|
88
|
+
# Example: Call OpenAI directly
|
|
89
|
+
import openai
|
|
90
|
+
client = openai.OpenAI()
|
|
91
|
+
response = client.chat.completions.create(
|
|
92
|
+
model="gpt-4o-mini",
|
|
93
|
+
messages=messages
|
|
94
|
+
)
|
|
95
|
+
return response.choices[0].message.content
|
|
96
|
+
|
|
97
|
+
# Or use the built-in OpenAI adapter
|
|
98
|
+
from praisonaiagents.lite import create_openai_llm_fn
|
|
99
|
+
llm_fn = create_openai_llm_fn(model="gpt-4o-mini")
|
|
100
|
+
|
|
101
|
+
# Create a lite agent
|
|
102
|
+
agent = LiteAgent(
|
|
103
|
+
name="MyAgent",
|
|
104
|
+
llm_fn=llm_fn,
|
|
105
|
+
instructions="You are a helpful assistant."
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
# Chat with the agent
|
|
109
|
+
response = agent.chat("Hello!")
|
|
110
|
+
print(response)
|
|
111
|
+
|
|
112
|
+
# Define and use tools
|
|
113
|
+
@tool
|
|
114
|
+
def add_numbers(a: int, b: int) -> int:
|
|
115
|
+
"""Add two numbers."""
|
|
116
|
+
return a + b
|
|
117
|
+
|
|
118
|
+
agent_with_tools = LiteAgent(
|
|
119
|
+
name="MathAgent",
|
|
120
|
+
llm_fn=llm_fn,
|
|
121
|
+
tools=[add_numbers]
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
# Execute tool directly
|
|
125
|
+
result = agent_with_tools.execute_tool("add_numbers", a=5, b=3)
|
|
126
|
+
print(f"Result: {result.output}") # Output: 8
|
|
127
|
+
'''
|
|
128
|
+
return example
|
|
129
|
+
|
|
130
|
+
def run_lite_agent(
|
|
131
|
+
self,
|
|
132
|
+
prompt: str,
|
|
133
|
+
model: str = "gpt-4o-mini",
|
|
134
|
+
provider: str = "openai"
|
|
135
|
+
) -> str:
|
|
136
|
+
"""
|
|
137
|
+
Run a lite agent with the given prompt.
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
prompt: The prompt to send to the agent
|
|
141
|
+
model: Model name to use
|
|
142
|
+
provider: LLM provider (openai, anthropic)
|
|
143
|
+
|
|
144
|
+
Returns:
|
|
145
|
+
Agent response
|
|
146
|
+
"""
|
|
147
|
+
try:
|
|
148
|
+
from praisonaiagents.lite import LiteAgent, create_openai_llm_fn, create_anthropic_llm_fn
|
|
149
|
+
|
|
150
|
+
# Create LLM function based on provider
|
|
151
|
+
if provider == "openai":
|
|
152
|
+
if not os.environ.get("OPENAI_API_KEY"):
|
|
153
|
+
return "Error: OPENAI_API_KEY not set"
|
|
154
|
+
llm_fn = create_openai_llm_fn(model=model)
|
|
155
|
+
elif provider == "anthropic":
|
|
156
|
+
if not os.environ.get("ANTHROPIC_API_KEY"):
|
|
157
|
+
return "Error: ANTHROPIC_API_KEY not set"
|
|
158
|
+
llm_fn = create_anthropic_llm_fn(model=model)
|
|
159
|
+
else:
|
|
160
|
+
return f"Error: Unknown provider '{provider}'. Use 'openai' or 'anthropic'."
|
|
161
|
+
|
|
162
|
+
# Create and run agent
|
|
163
|
+
agent = LiteAgent(
|
|
164
|
+
name="LiteCLIAgent",
|
|
165
|
+
llm_fn=llm_fn,
|
|
166
|
+
instructions="You are a helpful assistant. Keep responses concise."
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
return agent.chat(prompt)
|
|
170
|
+
|
|
171
|
+
except ImportError as e:
|
|
172
|
+
return f"Error: {e}"
|
|
173
|
+
except Exception as e:
|
|
174
|
+
return f"Error: {e}"
|
|
175
|
+
|
|
176
|
+
def handle(self, subcommand: str = "info", **kwargs) -> Any:
|
|
177
|
+
"""
|
|
178
|
+
Handle lite subcommands.
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
subcommand: One of run, info, example
|
|
182
|
+
**kwargs: Additional options (prompt, model, provider)
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
Results
|
|
186
|
+
"""
|
|
187
|
+
if subcommand == "info":
|
|
188
|
+
info = self.get_info()
|
|
189
|
+
if info.get("available"):
|
|
190
|
+
print("praisonaiagents.lite - Lightweight Agent Package")
|
|
191
|
+
print("=" * 50)
|
|
192
|
+
print("\nClasses:", ", ".join(info["classes"]))
|
|
193
|
+
print("Decorators:", ", ".join(info["decorators"]))
|
|
194
|
+
print("Helpers:", ", ".join(info["helpers"]))
|
|
195
|
+
print("\nFeatures:")
|
|
196
|
+
for feature in info["features"]:
|
|
197
|
+
print(f" • {feature}")
|
|
198
|
+
else:
|
|
199
|
+
print(f"Lite package not available: {info.get('error')}")
|
|
200
|
+
return info
|
|
201
|
+
|
|
202
|
+
elif subcommand == "example":
|
|
203
|
+
example = self.show_example()
|
|
204
|
+
print(example)
|
|
205
|
+
return example
|
|
206
|
+
|
|
207
|
+
elif subcommand == "run":
|
|
208
|
+
prompt = kwargs.get("prompt", "Hello!")
|
|
209
|
+
model = kwargs.get("model", "gpt-4o-mini")
|
|
210
|
+
provider = kwargs.get("provider", "openai")
|
|
211
|
+
|
|
212
|
+
response = self.run_lite_agent(prompt, model, provider)
|
|
213
|
+
print(response)
|
|
214
|
+
return response
|
|
215
|
+
|
|
216
|
+
else:
|
|
217
|
+
print(f"Unknown subcommand: {subcommand}")
|
|
218
|
+
print("Available: info, example, run")
|
|
219
|
+
return None
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def run_lite_command(args) -> int:
|
|
223
|
+
"""
|
|
224
|
+
Run lite command from CLI args.
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
args: Parsed CLI arguments
|
|
228
|
+
|
|
229
|
+
Returns:
|
|
230
|
+
Exit code (0 for success)
|
|
231
|
+
"""
|
|
232
|
+
handler = LiteHandler()
|
|
233
|
+
subcommand = getattr(args, 'lite_command', 'info')
|
|
234
|
+
|
|
235
|
+
kwargs = {}
|
|
236
|
+
if hasattr(args, 'prompt'):
|
|
237
|
+
kwargs['prompt'] = args.prompt
|
|
238
|
+
if hasattr(args, 'model'):
|
|
239
|
+
kwargs['model'] = args.model
|
|
240
|
+
if hasattr(args, 'provider'):
|
|
241
|
+
kwargs['provider'] = args.provider
|
|
242
|
+
|
|
243
|
+
result = handler.handle(subcommand, **kwargs)
|
|
244
|
+
return 0 if result else 1
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"""
|
|
2
|
+
LSP CLI handler for PraisonAI.
|
|
3
|
+
|
|
4
|
+
Provides LSP service lifecycle commands:
|
|
5
|
+
- lsp start: Start LSP server(s)
|
|
6
|
+
- lsp stop: Stop LSP server(s)
|
|
7
|
+
- lsp status: Show status
|
|
8
|
+
- lsp logs: Show recent logs
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import asyncio
|
|
13
|
+
import json
|
|
14
|
+
import logging
|
|
15
|
+
from typing import List
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class LSPHandler:
|
|
21
|
+
"""Handler for LSP CLI commands."""
|
|
22
|
+
|
|
23
|
+
@staticmethod
|
|
24
|
+
def setup_subparser(subparsers) -> None:
|
|
25
|
+
"""Set up the lsp subcommand parser."""
|
|
26
|
+
lsp_parser = subparsers.add_parser(
|
|
27
|
+
"lsp",
|
|
28
|
+
help="LSP service lifecycle management",
|
|
29
|
+
description="Manage Language Server Protocol servers"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
lsp_subparsers = lsp_parser.add_subparsers(dest="lsp_command", help="LSP subcommands")
|
|
33
|
+
|
|
34
|
+
# lsp start
|
|
35
|
+
start_parser = lsp_subparsers.add_parser("start", help="Start LSP server(s)")
|
|
36
|
+
start_parser.add_argument(
|
|
37
|
+
"--language", "-l",
|
|
38
|
+
type=str,
|
|
39
|
+
help="Language to start (default: auto-detect)"
|
|
40
|
+
)
|
|
41
|
+
start_parser.add_argument(
|
|
42
|
+
"--workspace", "-w",
|
|
43
|
+
type=str,
|
|
44
|
+
default=".",
|
|
45
|
+
help="Workspace root directory"
|
|
46
|
+
)
|
|
47
|
+
start_parser.add_argument("--json", action="store_true", help="Output JSON")
|
|
48
|
+
start_parser.set_defaults(func=LSPHandler.handle_start)
|
|
49
|
+
|
|
50
|
+
# lsp stop
|
|
51
|
+
stop_parser = lsp_subparsers.add_parser("stop", help="Stop LSP server(s)")
|
|
52
|
+
stop_parser.add_argument("--json", action="store_true", help="Output JSON")
|
|
53
|
+
stop_parser.set_defaults(func=LSPHandler.handle_stop)
|
|
54
|
+
|
|
55
|
+
# lsp status
|
|
56
|
+
status_parser = lsp_subparsers.add_parser("status", help="Show LSP status")
|
|
57
|
+
status_parser.add_argument(
|
|
58
|
+
"--workspace", "-w",
|
|
59
|
+
type=str,
|
|
60
|
+
default=".",
|
|
61
|
+
help="Workspace root directory"
|
|
62
|
+
)
|
|
63
|
+
status_parser.add_argument("--json", action="store_true", help="Output JSON")
|
|
64
|
+
status_parser.set_defaults(func=LSPHandler.handle_status)
|
|
65
|
+
|
|
66
|
+
# lsp logs
|
|
67
|
+
logs_parser = lsp_subparsers.add_parser("logs", help="Show recent logs")
|
|
68
|
+
logs_parser.add_argument(
|
|
69
|
+
"--tail", "-n",
|
|
70
|
+
type=int,
|
|
71
|
+
default=50,
|
|
72
|
+
help="Number of lines to show"
|
|
73
|
+
)
|
|
74
|
+
logs_parser.add_argument("--json", action="store_true", help="Output JSON")
|
|
75
|
+
logs_parser.set_defaults(func=LSPHandler.handle_logs)
|
|
76
|
+
|
|
77
|
+
@staticmethod
|
|
78
|
+
def handle_start(args: argparse.Namespace) -> int:
|
|
79
|
+
"""Handle lsp start command."""
|
|
80
|
+
return asyncio.run(LSPHandler._run_start(args))
|
|
81
|
+
|
|
82
|
+
@staticmethod
|
|
83
|
+
async def _run_start(args: argparse.Namespace) -> int:
|
|
84
|
+
"""Start LSP server."""
|
|
85
|
+
from .interactive_runtime import create_runtime
|
|
86
|
+
|
|
87
|
+
runtime = create_runtime(
|
|
88
|
+
workspace=args.workspace,
|
|
89
|
+
lsp=True,
|
|
90
|
+
acp=False
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
try:
|
|
94
|
+
await runtime.start()
|
|
95
|
+
|
|
96
|
+
result = {
|
|
97
|
+
"action": "start",
|
|
98
|
+
"lsp_ready": runtime.lsp_ready,
|
|
99
|
+
"lsp_status": runtime._lsp_state.status.value,
|
|
100
|
+
"workspace": args.workspace,
|
|
101
|
+
"language": getattr(args, 'language', None) or "auto-detected"
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if runtime._lsp_state.error:
|
|
105
|
+
result["error"] = runtime._lsp_state.error
|
|
106
|
+
|
|
107
|
+
LSPHandler._output_result(result, args.json)
|
|
108
|
+
|
|
109
|
+
# Keep running if started successfully
|
|
110
|
+
if runtime.lsp_ready:
|
|
111
|
+
if not args.json:
|
|
112
|
+
print("\nLSP server running. Press Ctrl+C to stop.")
|
|
113
|
+
try:
|
|
114
|
+
while True:
|
|
115
|
+
await asyncio.sleep(1)
|
|
116
|
+
except KeyboardInterrupt:
|
|
117
|
+
pass
|
|
118
|
+
|
|
119
|
+
return 0 if runtime.lsp_ready else 1
|
|
120
|
+
|
|
121
|
+
finally:
|
|
122
|
+
await runtime.stop()
|
|
123
|
+
|
|
124
|
+
@staticmethod
|
|
125
|
+
def handle_stop(args: argparse.Namespace) -> int:
|
|
126
|
+
"""Handle lsp stop command."""
|
|
127
|
+
result = {
|
|
128
|
+
"action": "stop",
|
|
129
|
+
"message": "LSP servers stopped"
|
|
130
|
+
}
|
|
131
|
+
LSPHandler._output_result(result, args.json)
|
|
132
|
+
return 0
|
|
133
|
+
|
|
134
|
+
@staticmethod
|
|
135
|
+
def handle_status(args: argparse.Namespace) -> int:
|
|
136
|
+
"""Handle lsp status command."""
|
|
137
|
+
return asyncio.run(LSPHandler._run_status(args))
|
|
138
|
+
|
|
139
|
+
@staticmethod
|
|
140
|
+
async def _run_status(args: argparse.Namespace) -> int:
|
|
141
|
+
"""Check LSP status."""
|
|
142
|
+
from .interactive_runtime import create_runtime
|
|
143
|
+
|
|
144
|
+
runtime = create_runtime(
|
|
145
|
+
workspace=args.workspace,
|
|
146
|
+
lsp=True,
|
|
147
|
+
acp=False
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
try:
|
|
151
|
+
await runtime.start()
|
|
152
|
+
|
|
153
|
+
result = {
|
|
154
|
+
"lsp_enabled": True,
|
|
155
|
+
"lsp_ready": runtime.lsp_ready,
|
|
156
|
+
"lsp_status": runtime._lsp_state.status.value,
|
|
157
|
+
"workspace": args.workspace
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if runtime._lsp_state.error:
|
|
161
|
+
result["error"] = runtime._lsp_state.error
|
|
162
|
+
|
|
163
|
+
LSPHandler._output_result(result, args.json)
|
|
164
|
+
return 0 if runtime.lsp_ready else 1
|
|
165
|
+
|
|
166
|
+
finally:
|
|
167
|
+
await runtime.stop()
|
|
168
|
+
|
|
169
|
+
@staticmethod
|
|
170
|
+
def handle_logs(args: argparse.Namespace) -> int:
|
|
171
|
+
"""Handle lsp logs command."""
|
|
172
|
+
result = {
|
|
173
|
+
"action": "logs",
|
|
174
|
+
"tail": args.tail,
|
|
175
|
+
"logs": [],
|
|
176
|
+
"message": "LSP logging not yet implemented"
|
|
177
|
+
}
|
|
178
|
+
LSPHandler._output_result(result, args.json)
|
|
179
|
+
return 0
|
|
180
|
+
|
|
181
|
+
@staticmethod
|
|
182
|
+
def _output_result(result: dict, as_json: bool) -> None:
|
|
183
|
+
"""Output result in appropriate format."""
|
|
184
|
+
if as_json:
|
|
185
|
+
print(json.dumps(result, indent=2, default=str))
|
|
186
|
+
else:
|
|
187
|
+
for key, value in result.items():
|
|
188
|
+
print(f"{key}: {value}")
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def run_lsp_command(args: List[str]) -> int:
|
|
192
|
+
"""Run lsp command from CLI."""
|
|
193
|
+
parser = argparse.ArgumentParser(prog="praisonai lsp")
|
|
194
|
+
subparsers = parser.add_subparsers(dest="lsp_command", help="LSP subcommands")
|
|
195
|
+
|
|
196
|
+
# lsp start
|
|
197
|
+
start_parser = subparsers.add_parser("start", help="Start LSP server(s)")
|
|
198
|
+
start_parser.add_argument("--language", "-l", type=str)
|
|
199
|
+
start_parser.add_argument("--workspace", "-w", type=str, default=".")
|
|
200
|
+
start_parser.add_argument("--json", action="store_true")
|
|
201
|
+
start_parser.set_defaults(func=LSPHandler.handle_start)
|
|
202
|
+
|
|
203
|
+
# lsp stop
|
|
204
|
+
stop_parser = subparsers.add_parser("stop", help="Stop LSP server(s)")
|
|
205
|
+
stop_parser.add_argument("--json", action="store_true")
|
|
206
|
+
stop_parser.set_defaults(func=LSPHandler.handle_stop)
|
|
207
|
+
|
|
208
|
+
# lsp status
|
|
209
|
+
status_parser = subparsers.add_parser("status", help="Show LSP status")
|
|
210
|
+
status_parser.add_argument("--workspace", "-w", type=str, default=".")
|
|
211
|
+
status_parser.add_argument("--json", action="store_true")
|
|
212
|
+
status_parser.set_defaults(func=LSPHandler.handle_status)
|
|
213
|
+
|
|
214
|
+
# lsp logs
|
|
215
|
+
logs_parser = subparsers.add_parser("logs", help="Show recent logs")
|
|
216
|
+
logs_parser.add_argument("--tail", "-n", type=int, default=50)
|
|
217
|
+
logs_parser.add_argument("--json", action="store_true")
|
|
218
|
+
logs_parser.set_defaults(func=LSPHandler.handle_logs)
|
|
219
|
+
|
|
220
|
+
parsed = parser.parse_args(args)
|
|
221
|
+
if hasattr(parsed, 'func'):
|
|
222
|
+
return parsed.func(parsed)
|
|
223
|
+
else:
|
|
224
|
+
parser.print_help()
|
|
225
|
+
return 0
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MCP Handler for CLI.
|
|
3
|
+
|
|
4
|
+
Provides Model Context Protocol server integration.
|
|
5
|
+
Usage: praisonai "prompt" --mcp "npx -y @modelcontextprotocol/server-filesystem ."
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import shlex
|
|
9
|
+
from typing import Any, Dict, Tuple, List
|
|
10
|
+
from .base import FlagHandler
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class MCPHandler(FlagHandler):
|
|
14
|
+
"""
|
|
15
|
+
Handler for --mcp flag.
|
|
16
|
+
|
|
17
|
+
Integrates MCP (Model Context Protocol) servers as tools for agents.
|
|
18
|
+
|
|
19
|
+
Example:
|
|
20
|
+
praisonai "List files" --mcp "npx -y @modelcontextprotocol/server-filesystem ."
|
|
21
|
+
praisonai "Search web" --mcp "npx -y @modelcontextprotocol/server-brave-search" --mcp-env "BRAVE_API_KEY=xxx"
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def feature_name(self) -> str:
|
|
26
|
+
return "mcp"
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def flag_name(self) -> str:
|
|
30
|
+
return "mcp"
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def flag_help(self) -> str:
|
|
34
|
+
return "MCP server command (e.g., 'npx -y @modelcontextprotocol/server-filesystem .')"
|
|
35
|
+
|
|
36
|
+
def check_dependencies(self) -> Tuple[bool, str]:
|
|
37
|
+
"""Check if MCP is available."""
|
|
38
|
+
try:
|
|
39
|
+
import importlib.util
|
|
40
|
+
if importlib.util.find_spec("praisonaiagents") is not None:
|
|
41
|
+
# Check if MCP module is available
|
|
42
|
+
from praisonaiagents import MCP
|
|
43
|
+
if MCP is not None:
|
|
44
|
+
return True, ""
|
|
45
|
+
return False, "MCP requires praisonaiagents with MCP support"
|
|
46
|
+
except ImportError:
|
|
47
|
+
return False, "praisonaiagents not installed. Install with: pip install praisonaiagents"
|
|
48
|
+
|
|
49
|
+
def parse_mcp_command(self, command: str, env_vars: str = None) -> Tuple[str, List[str], Dict[str, str]]:
|
|
50
|
+
"""
|
|
51
|
+
Parse MCP command string into command, args, and environment.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
command: Full MCP command string
|
|
55
|
+
env_vars: Optional comma-separated environment variables (KEY=value,KEY2=value2)
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
Tuple of (command, args, env_dict)
|
|
59
|
+
"""
|
|
60
|
+
# Parse command using shell-like splitting
|
|
61
|
+
parts = shlex.split(command)
|
|
62
|
+
if not parts:
|
|
63
|
+
return "", [], {}
|
|
64
|
+
|
|
65
|
+
cmd = parts[0]
|
|
66
|
+
args = parts[1:] if len(parts) > 1 else []
|
|
67
|
+
|
|
68
|
+
# Parse environment variables
|
|
69
|
+
env = {}
|
|
70
|
+
if env_vars:
|
|
71
|
+
for pair in env_vars.split(','):
|
|
72
|
+
if '=' in pair:
|
|
73
|
+
key, value = pair.split('=', 1)
|
|
74
|
+
env[key.strip()] = value.strip()
|
|
75
|
+
|
|
76
|
+
return cmd, args, env
|
|
77
|
+
|
|
78
|
+
def create_mcp_tools(self, command: str, env_vars: str = None, timeout: int = 30) -> Any:
|
|
79
|
+
"""
|
|
80
|
+
Create MCP tools from command.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
command: MCP server command
|
|
84
|
+
env_vars: Optional environment variables
|
|
85
|
+
timeout: Connection timeout in seconds
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
MCP instance or None if unavailable
|
|
89
|
+
"""
|
|
90
|
+
available, msg = self.check_dependencies()
|
|
91
|
+
if not available:
|
|
92
|
+
self.print_status(msg, "error")
|
|
93
|
+
return None
|
|
94
|
+
|
|
95
|
+
from praisonaiagents import MCP
|
|
96
|
+
|
|
97
|
+
cmd, args, env = self.parse_mcp_command(command, env_vars)
|
|
98
|
+
|
|
99
|
+
if not cmd:
|
|
100
|
+
self.print_status("Invalid MCP command", "error")
|
|
101
|
+
return None
|
|
102
|
+
|
|
103
|
+
try:
|
|
104
|
+
mcp = MCP(
|
|
105
|
+
command=cmd,
|
|
106
|
+
args=args,
|
|
107
|
+
env=env if env else None,
|
|
108
|
+
timeout=timeout
|
|
109
|
+
)
|
|
110
|
+
self.print_status(f"🔌 MCP server connected: {cmd}", "success")
|
|
111
|
+
return mcp
|
|
112
|
+
except Exception as e:
|
|
113
|
+
self.print_status(f"Failed to connect to MCP server: {e}", "error")
|
|
114
|
+
return None
|
|
115
|
+
|
|
116
|
+
def apply_to_agent_config(self, config: Dict[str, Any], flag_value: Any) -> Dict[str, Any]:
|
|
117
|
+
"""
|
|
118
|
+
Apply MCP configuration to agent config.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
config: Agent configuration dictionary
|
|
122
|
+
flag_value: MCP command string or dict with command and env
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
Modified configuration with MCP tools
|
|
126
|
+
"""
|
|
127
|
+
if not flag_value:
|
|
128
|
+
return config
|
|
129
|
+
|
|
130
|
+
# Handle both string and dict formats
|
|
131
|
+
if isinstance(flag_value, str):
|
|
132
|
+
mcp = self.create_mcp_tools(flag_value)
|
|
133
|
+
elif isinstance(flag_value, dict):
|
|
134
|
+
mcp = self.create_mcp_tools(
|
|
135
|
+
flag_value.get('command', ''),
|
|
136
|
+
flag_value.get('env', ''),
|
|
137
|
+
flag_value.get('timeout', 30)
|
|
138
|
+
)
|
|
139
|
+
else:
|
|
140
|
+
return config
|
|
141
|
+
|
|
142
|
+
if mcp:
|
|
143
|
+
# Add MCP tools to existing tools
|
|
144
|
+
existing_tools = config.get('tools', [])
|
|
145
|
+
if isinstance(existing_tools, list):
|
|
146
|
+
existing_tools.extend(list(mcp))
|
|
147
|
+
else:
|
|
148
|
+
existing_tools = list(mcp)
|
|
149
|
+
config['tools'] = existing_tools
|
|
150
|
+
config['_mcp_instance'] = mcp # Store for cleanup
|
|
151
|
+
|
|
152
|
+
return config
|
|
153
|
+
|
|
154
|
+
def execute(self, command: str = None, env_vars: str = None, **kwargs) -> Any:
|
|
155
|
+
"""
|
|
156
|
+
Execute MCP setup.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
command: MCP server command
|
|
160
|
+
env_vars: Environment variables
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
MCP instance or None
|
|
164
|
+
"""
|
|
165
|
+
if not command:
|
|
166
|
+
self.print_status("No MCP command provided", "error")
|
|
167
|
+
return None
|
|
168
|
+
|
|
169
|
+
return self.create_mcp_tools(command, env_vars)
|