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
praisonai/ui/colab.py
ADDED
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
from praisonaiagents import Agent, Task, PraisonAIAgents
|
|
2
|
+
import os
|
|
3
|
+
import importlib
|
|
4
|
+
import inspect
|
|
5
|
+
import yaml
|
|
6
|
+
import logging
|
|
7
|
+
from .callbacks import trigger_callback
|
|
8
|
+
import asyncio
|
|
9
|
+
import chainlit as cl
|
|
10
|
+
from queue import Queue
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
agent_file = "agents.yaml"
|
|
14
|
+
|
|
15
|
+
with open(agent_file, 'r') as f:
|
|
16
|
+
config = yaml.safe_load(f)
|
|
17
|
+
|
|
18
|
+
topic = "get from the message content from the chainlit user message"
|
|
19
|
+
|
|
20
|
+
# Create a message queue
|
|
21
|
+
message_queue = Queue()
|
|
22
|
+
|
|
23
|
+
async def process_message_queue():
|
|
24
|
+
"""Process messages in the queue and send them to Chainlit"""
|
|
25
|
+
while True:
|
|
26
|
+
try:
|
|
27
|
+
if not message_queue.empty():
|
|
28
|
+
msg_data = message_queue.get()
|
|
29
|
+
await cl.Message(**msg_data).send()
|
|
30
|
+
await asyncio.sleep(0.1) # Small delay to prevent busy waiting
|
|
31
|
+
except Exception as e:
|
|
32
|
+
logger.error(f"Error processing message queue: {e}")
|
|
33
|
+
|
|
34
|
+
def load_tools_from_tools_py():
|
|
35
|
+
"""
|
|
36
|
+
Imports and returns all contents from tools.py file.
|
|
37
|
+
Also adds the tools to the global namespace.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
list: A list of callable functions with proper formatting
|
|
41
|
+
"""
|
|
42
|
+
tools_list = []
|
|
43
|
+
try:
|
|
44
|
+
# Try to import tools.py from current directory
|
|
45
|
+
spec = importlib.util.spec_from_file_location("tools", "tools.py")
|
|
46
|
+
logger.info(f"Spec: {spec}")
|
|
47
|
+
if spec is None:
|
|
48
|
+
logger.info("tools.py not found in current directory")
|
|
49
|
+
return tools_list
|
|
50
|
+
|
|
51
|
+
module = importlib.util.module_from_spec(spec)
|
|
52
|
+
spec.loader.exec_module(module)
|
|
53
|
+
|
|
54
|
+
# Get all module attributes except private ones and classes
|
|
55
|
+
for name, obj in inspect.getmembers(module):
|
|
56
|
+
if (not name.startswith('_') and
|
|
57
|
+
callable(obj) and
|
|
58
|
+
not inspect.isclass(obj)):
|
|
59
|
+
# Add the function to global namespace
|
|
60
|
+
globals()[name] = obj
|
|
61
|
+
# Format the tool as an OpenAI function
|
|
62
|
+
tool = {
|
|
63
|
+
"type": "function",
|
|
64
|
+
"function": {
|
|
65
|
+
"name": name,
|
|
66
|
+
"description": obj.__doc__ or f"Function to {name.replace('_', ' ')}",
|
|
67
|
+
"parameters": {
|
|
68
|
+
"type": "object",
|
|
69
|
+
"properties": {
|
|
70
|
+
"query": {
|
|
71
|
+
"type": "string",
|
|
72
|
+
"description": "The search query to look up information about"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"required": ["query"]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
# Add formatted tool to tools list
|
|
80
|
+
tools_list.append(tool)
|
|
81
|
+
logger.info(f"Loaded and globalized tool function: {name}")
|
|
82
|
+
|
|
83
|
+
logger.info(f"Loaded {len(tools_list)} tool functions from tools.py")
|
|
84
|
+
logger.info(f"Tools list: {tools_list}")
|
|
85
|
+
|
|
86
|
+
except Exception as e:
|
|
87
|
+
logger.warning(f"Error loading tools from tools.py: {e}")
|
|
88
|
+
|
|
89
|
+
return tools_list
|
|
90
|
+
|
|
91
|
+
async def step_callback(step_details):
|
|
92
|
+
"""Callback for agent steps"""
|
|
93
|
+
logger.info(f"[CALLBACK DEBUG] Step callback triggered with details: {step_details}")
|
|
94
|
+
try:
|
|
95
|
+
# Queue message for agent response
|
|
96
|
+
if step_details.get("response"):
|
|
97
|
+
message_queue.put({
|
|
98
|
+
"content": f"Agent Response: {step_details.get('response')}",
|
|
99
|
+
"author": step_details.get("agent_name", "Agent")
|
|
100
|
+
})
|
|
101
|
+
logger.info("[CALLBACK DEBUG] Queued agent response message")
|
|
102
|
+
|
|
103
|
+
# Queue message for tool usage
|
|
104
|
+
if step_details.get("tool_name"):
|
|
105
|
+
message_queue.put({
|
|
106
|
+
"content": f"🛠️ Using tool: {step_details.get('tool_name')}",
|
|
107
|
+
"author": "System"
|
|
108
|
+
})
|
|
109
|
+
logger.info("[CALLBACK DEBUG] Queued tool usage message")
|
|
110
|
+
|
|
111
|
+
except Exception as e:
|
|
112
|
+
logger.error(f"[CALLBACK DEBUG] Error in step callback: {str(e)}", exc_info=True)
|
|
113
|
+
|
|
114
|
+
async def task_callback(task_output):
|
|
115
|
+
"""Callback for task completion"""
|
|
116
|
+
logger.info(f"[CALLBACK DEBUG] Task callback triggered with output: {task_output}")
|
|
117
|
+
try:
|
|
118
|
+
# Create message content
|
|
119
|
+
if hasattr(task_output, 'raw'):
|
|
120
|
+
content = task_output.raw
|
|
121
|
+
elif hasattr(task_output, 'content'):
|
|
122
|
+
content = task_output.content
|
|
123
|
+
else:
|
|
124
|
+
content = str(task_output)
|
|
125
|
+
|
|
126
|
+
# Queue the message
|
|
127
|
+
message_queue.put({
|
|
128
|
+
"content": f"Task Output: {content}",
|
|
129
|
+
"author": "Task"
|
|
130
|
+
})
|
|
131
|
+
logger.info("[CALLBACK DEBUG] Queued task completion message")
|
|
132
|
+
|
|
133
|
+
except Exception as e:
|
|
134
|
+
logger.error(f"[CALLBACK DEBUG] Error in task callback: {str(e)}", exc_info=True)
|
|
135
|
+
|
|
136
|
+
async def step_callback_wrapper(step_details):
|
|
137
|
+
logger.info(f"[CALLBACK DEBUG] Step callback wrapper triggered with details: {step_details}")
|
|
138
|
+
try:
|
|
139
|
+
# Check if we have a Chainlit context
|
|
140
|
+
if not cl.context.context_var.get():
|
|
141
|
+
logger.warning("[CALLBACK DEBUG] No Chainlit context available in wrapper")
|
|
142
|
+
return
|
|
143
|
+
logger.info("[CALLBACK DEBUG] Chainlit context found in wrapper")
|
|
144
|
+
|
|
145
|
+
# Create a message for the agent's response
|
|
146
|
+
if step_details.get("response"):
|
|
147
|
+
logger.info(f"[CALLBACK DEBUG] Sending agent response from wrapper: {step_details.get('response')}")
|
|
148
|
+
try:
|
|
149
|
+
await cl.Message(
|
|
150
|
+
content=f"{role_name}: {step_details.get('response')}",
|
|
151
|
+
author=role_name,
|
|
152
|
+
).send()
|
|
153
|
+
logger.info("[CALLBACK DEBUG] Successfully sent agent response message from wrapper")
|
|
154
|
+
except Exception as e:
|
|
155
|
+
logger.error(f"[CALLBACK DEBUG] Error sending agent response message from wrapper: {str(e)}")
|
|
156
|
+
|
|
157
|
+
# Create a message for any tool usage
|
|
158
|
+
if step_details.get("tool_name"):
|
|
159
|
+
logger.info(f"[CALLBACK DEBUG] Sending tool usage from wrapper: {step_details.get('tool_name')}")
|
|
160
|
+
try:
|
|
161
|
+
await cl.Message(
|
|
162
|
+
content=f"🛠️ {role_name} is using tool: {step_details.get('tool_name')}",
|
|
163
|
+
author="System",
|
|
164
|
+
).send()
|
|
165
|
+
logger.info("[CALLBACK DEBUG] Successfully sent tool usage message from wrapper")
|
|
166
|
+
except Exception as e:
|
|
167
|
+
logger.error(f"[CALLBACK DEBUG] Error sending tool usage message from wrapper: {str(e)}")
|
|
168
|
+
|
|
169
|
+
# Create a message for any thoughts or reasoning
|
|
170
|
+
if step_details.get("thought"):
|
|
171
|
+
logger.info(f"[CALLBACK DEBUG] Sending thought from wrapper: {step_details.get('thought')}")
|
|
172
|
+
try:
|
|
173
|
+
await cl.Message(
|
|
174
|
+
content=f"💭 {role_name}'s thought: {step_details.get('thought')}",
|
|
175
|
+
author=role_name,
|
|
176
|
+
).send()
|
|
177
|
+
logger.info("[CALLBACK DEBUG] Successfully sent thought message from wrapper")
|
|
178
|
+
except Exception as e:
|
|
179
|
+
logger.error(f"[CALLBACK DEBUG] Error sending thought message from wrapper: {str(e)}")
|
|
180
|
+
|
|
181
|
+
except Exception as e:
|
|
182
|
+
logger.error(f"[CALLBACK DEBUG] Error in step callback wrapper: {str(e)}", exc_info=True)
|
|
183
|
+
try:
|
|
184
|
+
await cl.Message(
|
|
185
|
+
content=f"Error in step callback: {str(e)}",
|
|
186
|
+
author="System",
|
|
187
|
+
).send()
|
|
188
|
+
except Exception as send_error:
|
|
189
|
+
logger.error(f"[CALLBACK DEBUG] Error sending error message: {str(send_error)}")
|
|
190
|
+
|
|
191
|
+
async def task_callback_wrapper(task_output):
|
|
192
|
+
logger.info(f"[CALLBACK DEBUG] Task callback wrapper triggered with output type: {type(task_output)}")
|
|
193
|
+
try:
|
|
194
|
+
# Check if we have a Chainlit context
|
|
195
|
+
if not cl.context.context_var.get():
|
|
196
|
+
logger.warning("[CALLBACK DEBUG] No Chainlit context available in task wrapper")
|
|
197
|
+
return
|
|
198
|
+
logger.info("[CALLBACK DEBUG] Chainlit context found in task wrapper")
|
|
199
|
+
|
|
200
|
+
# Create a message for task completion
|
|
201
|
+
if hasattr(task_output, 'raw'):
|
|
202
|
+
content = task_output.raw
|
|
203
|
+
logger.info("[CALLBACK DEBUG] Using raw output")
|
|
204
|
+
elif hasattr(task_output, 'content'):
|
|
205
|
+
content = task_output.content
|
|
206
|
+
logger.info("[CALLBACK DEBUG] Using content output")
|
|
207
|
+
else:
|
|
208
|
+
content = str(task_output)
|
|
209
|
+
logger.info("[CALLBACK DEBUG] Using string representation of output")
|
|
210
|
+
|
|
211
|
+
logger.info(f"[CALLBACK DEBUG] Sending task completion message from wrapper: {content[:100]}...")
|
|
212
|
+
try:
|
|
213
|
+
await cl.Message(
|
|
214
|
+
content=f"✅ {role_name} completed task:\n{content}",
|
|
215
|
+
author=role_name,
|
|
216
|
+
).send()
|
|
217
|
+
logger.info("[CALLBACK DEBUG] Successfully sent task completion message from wrapper")
|
|
218
|
+
except Exception as e:
|
|
219
|
+
logger.error(f"[CALLBACK DEBUG] Error sending task completion message from wrapper: {str(e)}")
|
|
220
|
+
|
|
221
|
+
# If there are any additional task details
|
|
222
|
+
if hasattr(task_output, 'details'):
|
|
223
|
+
logger.info("[CALLBACK DEBUG] Task has additional details")
|
|
224
|
+
try:
|
|
225
|
+
await cl.Message(
|
|
226
|
+
content=f"📝 Additional details:\n{task_output.details}",
|
|
227
|
+
author=role_name,
|
|
228
|
+
).send()
|
|
229
|
+
logger.info("[CALLBACK DEBUG] Successfully sent additional details message")
|
|
230
|
+
except Exception as e:
|
|
231
|
+
logger.error(f"[CALLBACK DEBUG] Error sending additional details message: {str(e)}")
|
|
232
|
+
|
|
233
|
+
except Exception as e:
|
|
234
|
+
logger.error(f"[CALLBACK DEBUG] Error in task callback wrapper: {str(e)}", exc_info=True)
|
|
235
|
+
try:
|
|
236
|
+
await cl.Message(
|
|
237
|
+
content=f"Error in task callback: {str(e)}",
|
|
238
|
+
author="System",
|
|
239
|
+
).send()
|
|
240
|
+
except Exception as send_error:
|
|
241
|
+
logger.error(f"[CALLBACK DEBUG] Error sending error message: {str(send_error)}")
|
|
242
|
+
|
|
243
|
+
def sync_task_callback_wrapper(task_output):
|
|
244
|
+
logger.info("[CALLBACK DEBUG] Sync task callback wrapper triggered")
|
|
245
|
+
try:
|
|
246
|
+
# Create a new event loop for this thread if there isn't one
|
|
247
|
+
try:
|
|
248
|
+
loop = asyncio.get_event_loop()
|
|
249
|
+
logger.info("[CALLBACK DEBUG] Got existing event loop")
|
|
250
|
+
except RuntimeError:
|
|
251
|
+
loop = asyncio.new_event_loop()
|
|
252
|
+
asyncio.set_event_loop(loop)
|
|
253
|
+
logger.info("[CALLBACK DEBUG] Created new event loop")
|
|
254
|
+
|
|
255
|
+
if loop.is_running():
|
|
256
|
+
# If loop is running, schedule the callback
|
|
257
|
+
logger.info("[CALLBACK DEBUG] Loop is running, scheduling callback")
|
|
258
|
+
asyncio.run_coroutine_threadsafe(
|
|
259
|
+
task_callback_wrapper(task_output),
|
|
260
|
+
loop
|
|
261
|
+
)
|
|
262
|
+
else:
|
|
263
|
+
# If loop is not running, run it directly
|
|
264
|
+
logger.info("[CALLBACK DEBUG] Loop is not running, running callback directly")
|
|
265
|
+
loop.run_until_complete(task_callback_wrapper(task_output))
|
|
266
|
+
|
|
267
|
+
except Exception as e:
|
|
268
|
+
logger.error(f"[CALLBACK DEBUG] Error in sync task callback: {str(e)}", exc_info=True)
|
|
269
|
+
|
|
270
|
+
def sync_step_callback_wrapper(step_details):
|
|
271
|
+
logger.info("[CALLBACK DEBUG] Sync step callback wrapper triggered")
|
|
272
|
+
try:
|
|
273
|
+
# Create a new event loop for this thread if there isn't one
|
|
274
|
+
try:
|
|
275
|
+
loop = asyncio.get_event_loop()
|
|
276
|
+
logger.info("[CALLBACK DEBUG] Got existing event loop")
|
|
277
|
+
except RuntimeError:
|
|
278
|
+
loop = asyncio.new_event_loop()
|
|
279
|
+
asyncio.set_event_loop(loop)
|
|
280
|
+
logger.info("[CALLBACK DEBUG] Created new event loop")
|
|
281
|
+
|
|
282
|
+
if loop.is_running():
|
|
283
|
+
# If loop is running, schedule the callback
|
|
284
|
+
logger.info("[CALLBACK DEBUG] Loop is running, scheduling callback")
|
|
285
|
+
asyncio.run_coroutine_threadsafe(
|
|
286
|
+
step_callback_wrapper(step_details),
|
|
287
|
+
loop
|
|
288
|
+
)
|
|
289
|
+
else:
|
|
290
|
+
# If loop is not running, run it directly
|
|
291
|
+
logger.info("[CALLBACK DEBUG] Loop is not running, running callback directly")
|
|
292
|
+
loop.run_until_complete(step_callback_wrapper(step_details))
|
|
293
|
+
|
|
294
|
+
except Exception as e:
|
|
295
|
+
logger.error(f"[CALLBACK DEBUG] Error in sync step callback: {str(e)}", exc_info=True)
|
|
296
|
+
|
|
297
|
+
async def ui_run_praisonai(config, topic, tools_dict):
|
|
298
|
+
"""Run PraisonAI with the given configuration and topic."""
|
|
299
|
+
logger = logging.getLogger(__name__)
|
|
300
|
+
logger.setLevel(logging.DEBUG)
|
|
301
|
+
agents = {}
|
|
302
|
+
tasks = []
|
|
303
|
+
tasks_dict = {}
|
|
304
|
+
|
|
305
|
+
try:
|
|
306
|
+
# Start message queue processor
|
|
307
|
+
queue_processor = asyncio.create_task(process_message_queue())
|
|
308
|
+
|
|
309
|
+
# Create agents for each role
|
|
310
|
+
for role, details in config['roles'].items():
|
|
311
|
+
# Format the role name and other details
|
|
312
|
+
role_name = details.get('name', role).format(topic=topic)
|
|
313
|
+
role_filled = details.get('role', role).format(topic=topic)
|
|
314
|
+
goal_filled = details['goal'].format(topic=topic)
|
|
315
|
+
backstory_filled = details['backstory'].format(topic=topic)
|
|
316
|
+
|
|
317
|
+
# Test message to verify Chainlit is working
|
|
318
|
+
await cl.Message(
|
|
319
|
+
content=f"[DEBUG] Creating agent: {role_name}",
|
|
320
|
+
author="System"
|
|
321
|
+
).send()
|
|
322
|
+
|
|
323
|
+
# Create a sync wrapper for the step callback
|
|
324
|
+
def step_callback_sync(step_details):
|
|
325
|
+
try:
|
|
326
|
+
# Create a new event loop for this thread
|
|
327
|
+
loop = asyncio.new_event_loop()
|
|
328
|
+
asyncio.set_event_loop(loop)
|
|
329
|
+
|
|
330
|
+
# Add agent name to step details
|
|
331
|
+
step_details["agent_name"] = role_name
|
|
332
|
+
|
|
333
|
+
# Run the callback
|
|
334
|
+
loop.run_until_complete(step_callback(step_details))
|
|
335
|
+
loop.close()
|
|
336
|
+
except Exception as e:
|
|
337
|
+
logger.error(f"[CALLBACK DEBUG] Error in step callback: {str(e)}", exc_info=True)
|
|
338
|
+
|
|
339
|
+
agent = Agent(
|
|
340
|
+
name=role_name,
|
|
341
|
+
role=role_filled,
|
|
342
|
+
goal=goal_filled,
|
|
343
|
+
backstory=backstory_filled,
|
|
344
|
+
llm=details.get('llm', 'gpt-5-nano'),
|
|
345
|
+
verbose=True,
|
|
346
|
+
allow_delegation=details.get('allow_delegation', False),
|
|
347
|
+
max_iter=details.get('max_iter', 15),
|
|
348
|
+
max_rpm=details.get('max_rpm'),
|
|
349
|
+
max_execution_time=details.get('max_execution_time'),
|
|
350
|
+
cache=details.get('cache', True),
|
|
351
|
+
step_callback=step_callback_sync
|
|
352
|
+
)
|
|
353
|
+
agents[role] = agent
|
|
354
|
+
|
|
355
|
+
# Create tasks for each role
|
|
356
|
+
for role, details in config['roles'].items():
|
|
357
|
+
agent = agents[role]
|
|
358
|
+
tools_list = []
|
|
359
|
+
|
|
360
|
+
# Get tools for this role
|
|
361
|
+
for tool_name in details.get('tools', []):
|
|
362
|
+
if tool_name in tools_dict:
|
|
363
|
+
tool_func = tools_dict[tool_name]
|
|
364
|
+
tools_list.append(tool_func)
|
|
365
|
+
|
|
366
|
+
# Create tasks for the agent
|
|
367
|
+
for task_name, task_details in details.get('tasks', {}).items():
|
|
368
|
+
description_filled = task_details['description'].format(topic=topic)
|
|
369
|
+
expected_output_filled = task_details['expected_output'].format(topic=topic)
|
|
370
|
+
|
|
371
|
+
# Test message to verify task creation
|
|
372
|
+
await cl.Message(
|
|
373
|
+
content=f"[DEBUG] Created task: {task_name} for agent {role_name}",
|
|
374
|
+
author="System"
|
|
375
|
+
).send()
|
|
376
|
+
|
|
377
|
+
# Create a sync wrapper for the task callback
|
|
378
|
+
def task_callback_sync(task_output):
|
|
379
|
+
try:
|
|
380
|
+
# Create a new event loop for this thread
|
|
381
|
+
loop = asyncio.new_event_loop()
|
|
382
|
+
asyncio.set_event_loop(loop)
|
|
383
|
+
|
|
384
|
+
# Run the callback
|
|
385
|
+
loop.run_until_complete(task_callback(task_output))
|
|
386
|
+
loop.close()
|
|
387
|
+
except Exception as e:
|
|
388
|
+
logger.error(f"[CALLBACK DEBUG] Error in task callback: {str(e)}", exc_info=True)
|
|
389
|
+
|
|
390
|
+
task = Task(
|
|
391
|
+
description=description_filled,
|
|
392
|
+
expected_output=expected_output_filled,
|
|
393
|
+
agent=agent,
|
|
394
|
+
tools=tools_list,
|
|
395
|
+
async_execution=True,
|
|
396
|
+
context=[],
|
|
397
|
+
config=task_details.get('config', {}),
|
|
398
|
+
output_json=task_details.get('output_json'),
|
|
399
|
+
output_pydantic=task_details.get('output_pydantic'),
|
|
400
|
+
output_file=task_details.get('output_file', ""),
|
|
401
|
+
callback=task_callback_sync,
|
|
402
|
+
create_directory=task_details.get('create_directory', False)
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
tasks.append(task)
|
|
406
|
+
tasks_dict[task_name] = task
|
|
407
|
+
|
|
408
|
+
# Set up task contexts
|
|
409
|
+
for role, details in config['roles'].items():
|
|
410
|
+
for task_name, task_details in details.get('tasks', {}).items():
|
|
411
|
+
task = tasks_dict[task_name]
|
|
412
|
+
context_tasks = [tasks_dict[ctx] for ctx in task_details.get('context', [])
|
|
413
|
+
if ctx in tasks_dict]
|
|
414
|
+
task.context = context_tasks
|
|
415
|
+
|
|
416
|
+
# Send the start message
|
|
417
|
+
await cl.Message(
|
|
418
|
+
content="Starting PraisonAI agents execution...",
|
|
419
|
+
author="System"
|
|
420
|
+
).send()
|
|
421
|
+
|
|
422
|
+
# Create and run the PraisonAI agents
|
|
423
|
+
if config.get('process') == 'hierarchical':
|
|
424
|
+
crew = PraisonAIAgents(
|
|
425
|
+
agents=list(agents.values()),
|
|
426
|
+
tasks=tasks,
|
|
427
|
+
verbose=True,
|
|
428
|
+
process="hierarchical",
|
|
429
|
+
manager_llm=config.get('manager_llm', 'gpt-5-nano')
|
|
430
|
+
)
|
|
431
|
+
else:
|
|
432
|
+
crew = PraisonAIAgents(
|
|
433
|
+
agents=list(agents.values()),
|
|
434
|
+
tasks=tasks,
|
|
435
|
+
verbose=2
|
|
436
|
+
)
|
|
437
|
+
|
|
438
|
+
# Store the crew in the user session
|
|
439
|
+
cl.user_session.set("crew", crew)
|
|
440
|
+
|
|
441
|
+
# Run the agents in a separate thread
|
|
442
|
+
loop = asyncio.get_event_loop()
|
|
443
|
+
response = await loop.run_in_executor(None, crew.start)
|
|
444
|
+
|
|
445
|
+
logger.debug(f"[CALLBACK DEBUG] Result: {response}")
|
|
446
|
+
|
|
447
|
+
# Convert response to string if it's not already
|
|
448
|
+
if hasattr(response, 'raw'):
|
|
449
|
+
result = response.raw
|
|
450
|
+
elif hasattr(response, 'content'):
|
|
451
|
+
result = response.content
|
|
452
|
+
else:
|
|
453
|
+
result = str(response)
|
|
454
|
+
|
|
455
|
+
# Send the completion message
|
|
456
|
+
await cl.Message(
|
|
457
|
+
content="PraisonAI agents execution completed.",
|
|
458
|
+
author="System"
|
|
459
|
+
).send()
|
|
460
|
+
|
|
461
|
+
# After getting the response, wait a bit for remaining messages
|
|
462
|
+
await asyncio.sleep(1) # Give time for final messages to be processed
|
|
463
|
+
queue_processor.cancel() # Stop the queue processor
|
|
464
|
+
|
|
465
|
+
return result
|
|
466
|
+
|
|
467
|
+
except Exception as e:
|
|
468
|
+
error_msg = f"Error in ui_run_praisonai: {str(e)}"
|
|
469
|
+
logger.error(error_msg, exc_info=True)
|
|
470
|
+
await cl.Message(
|
|
471
|
+
content=error_msg,
|
|
472
|
+
author="System"
|
|
473
|
+
).send()
|
|
474
|
+
raise
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import logging
|
|
3
|
+
from dotenv import load_dotenv
|
|
4
|
+
import chainlit as cl
|
|
5
|
+
from chainlit.types import ThreadDict
|
|
6
|
+
import yaml
|
|
7
|
+
import sys
|
|
8
|
+
import os
|
|
9
|
+
from datetime import datetime
|
|
10
|
+
|
|
11
|
+
# Add the parent directory to sys.path to allow imports
|
|
12
|
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
|
13
|
+
|
|
14
|
+
from praisonai.ui.colab import ui_run_praisonai, load_tools_from_tools_py
|
|
15
|
+
from praisonai.ui.callbacks import callback, trigger_callback
|
|
16
|
+
|
|
17
|
+
# Load environment variables
|
|
18
|
+
load_dotenv()
|
|
19
|
+
|
|
20
|
+
# Set up logging
|
|
21
|
+
logger = logging.getLogger(__name__)
|
|
22
|
+
log_level = os.getenv("LOGLEVEL", "INFO").upper()
|
|
23
|
+
logger.setLevel(log_level)
|
|
24
|
+
|
|
25
|
+
# Load agent configuration
|
|
26
|
+
agent_file = "agents.yaml"
|
|
27
|
+
with open(agent_file, 'r') as f:
|
|
28
|
+
config = yaml.safe_load(f)
|
|
29
|
+
|
|
30
|
+
# Load tools
|
|
31
|
+
tools_dict = load_tools_from_tools_py()
|
|
32
|
+
|
|
33
|
+
@cl.on_message
|
|
34
|
+
async def main(message: cl.Message):
|
|
35
|
+
"""Main message handler for Chainlit"""
|
|
36
|
+
try:
|
|
37
|
+
logger.info(f"Processing message: {message.content}")
|
|
38
|
+
await cl.Message(
|
|
39
|
+
content=f"🔄 Processing your request about: {message.content}...",
|
|
40
|
+
author="System"
|
|
41
|
+
).send()
|
|
42
|
+
|
|
43
|
+
await cl.Message(
|
|
44
|
+
content="Using Running PraisonAI Agents...",
|
|
45
|
+
author="System"
|
|
46
|
+
).send()
|
|
47
|
+
|
|
48
|
+
# Run PraisonAI with the message content as the topic
|
|
49
|
+
result = await ui_run_praisonai(config, message.content, tools_dict)
|
|
50
|
+
|
|
51
|
+
# Send the final result
|
|
52
|
+
await cl.Message(
|
|
53
|
+
content=result,
|
|
54
|
+
author="System"
|
|
55
|
+
).send()
|
|
56
|
+
|
|
57
|
+
except Exception as e:
|
|
58
|
+
error_msg = f"Error running PraisonAI agents: {str(e)}"
|
|
59
|
+
logger.error(error_msg, exc_info=True)
|
|
60
|
+
await cl.Message(
|
|
61
|
+
content=error_msg,
|
|
62
|
+
author="System"
|
|
63
|
+
).send()
|
|
64
|
+
|
|
65
|
+
@cl.on_chat_start
|
|
66
|
+
async def start():
|
|
67
|
+
"""Handler for chat start"""
|
|
68
|
+
await cl.Message(
|
|
69
|
+
content="👋 Welcome! I'm your AI assistant. What would you like to work on?",
|
|
70
|
+
author="System"
|
|
71
|
+
).send()
|
|
72
|
+
|
|
73
|
+
# Authentication setup (optional)
|
|
74
|
+
if os.getenv("CHAINLIT_AUTH_SECRET"):
|
|
75
|
+
@cl.password_auth_callback
|
|
76
|
+
def auth_callback(username: str, password: str) -> cl.User:
|
|
77
|
+
# Replace with your authentication logic
|
|
78
|
+
if username == os.getenv("CHAINLIT_USERNAME", "admin") and \
|
|
79
|
+
password == os.getenv("CHAINLIT_PASSWORD", "admin"):
|
|
80
|
+
return cl.User(identifier=username, metadata={"role": "user"})
|
|
81
|
+
return None
|