Compare commits

...
Author SHA1 Message Date
MervinPraison fe87b9514e feat: add deep profiling benchmarks for Agent initialization
- deep_profile.py: cProfile analysis for 5000 agent creations
- deep_profile_bench.py: Combined timing and profiling for 1000 agents
- Helps identify performance bottlenecks in Agent.__init__
2026-04-02 19:49:16 +01:00
MervinPraison fec0b5fa32 feat: add @lru_cache to get_defaults_config for performance
- Cache defaults config to avoid repeated file I/O
- Add performance test files for benchmarking
- Further optimizes Agent initialization performance
2026-04-02 19:17:03 +01:00
MervinPraison c8a3881dda feat: JIT hydration optimization for Agent initialization
- Store raw params in __init__ for lazy config resolution
- Update OUTPUT, EXECUTION, CACHING, MEMORY, KNOWLEDGE, PLANNING, REFLECTION, WEB to use raw params
- Reduce eager config resolution overhead
- Benchmark shows 30µs initialization (down from previous baseline)
- Add smoke test for JIT hydration
- Phase 1 of incremental optimization plan

Fixes #performance
2026-04-02 18:51:31 +01:00
MervinPraison bfe3d94bad Release v4.5.112 2026-04-02 10:36:06 +01:00
7ae6c6d19c fix(sandbox): update sandlock integration to use real API surface (#1259)
* fix(sandbox): update sandlock integration to use real API surface

- Replace sandlock.is_available() with landlock_abi_version() >= 6 check
- Remove non-existent TimeoutError and SecurityViolationError exception handling
- Remove invalid max_cpu_time_seconds parameter from Policy constructor
- Update sandbox.run() to only pass cmd and timeout (remove env/cwd)
- Update tests to use correct API mocks

Fixes #1258

Co-authored-by: Mervin Praison <[email protected]>

* fix(sandbox): fix ABI version threshold, remove dead except block, unused var, and fix test mocks

Agent-Logs-Url: https://github.com/MervinPraison/PraisonAI/sessions/ee8122be-e5f3-47dd-bcb6-c0994df15169

Co-authored-by: MervinPraison <[email protected]>

* fix(sandbox): implement proper sandlock Result status mapping and improve test reliability

- Fix exit_code status mapping: Check result.success and exit_code before returning SandboxStatus.COMPLETED
- Update test mocks to return proper Result objects with success/exit_code instead of raising exceptions
- Add integration test that exercises real sandlock API if available
- Address reviewer feedback from CodeRabbit, Qodo, Gemini, and Copilot

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: MervinPraison <[email protected]>

---------

Co-authored-by: MervinPraison <[email protected]>
Co-authored-by: Mervin Praison <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
2026-04-02 10:34:25 +01:00
MervinPraison cc962c96d4 fix(workflows): robustly match copilot bot string to correctly chain claude 2026-04-02 10:29:06 +01:00
MervinPraison d5a55aaf4b Release v4.5.111 2026-04-02 07:47:12 +01:00
MervinPraison a02a7209a9 Allow external users to trigger Claude Code 2026-04-02 07:31:57 +01:00
MervinPraison 0e55b36056 refactor(tools): replace list_directory with list_files and tidy code
Updated the tools in multiple example scripts to use `list_files` instead of `list_directory`. Removed unnecessary global variables and functions in `shell_tools.py` for better clarity and performance. Updated the `approval` flag in agent configurations to `False` for consistency across examples.
2026-04-01 21:01:39 +01:00
MervinPraison d89e467257 feat(docs): add image and quote from Elon Musk to README
Added a new image highlighting PraisonAI shared by Elon Musk, along with a quote for better engagement and visibility.
2026-04-01 20:46:14 +01:00
MervinPraison 1e2a5ef12d chore(workflows): update email configuration across workflows
Updated the user email in multiple GitHub workflows to a no-reply address for better privacy. This change ensures consistency across the repository's automation scripts.

fix(examples): update web configuration in agent examples

Modified web configuration in `agent_centric_api.py` examples to utilize `WebConfig`. This enhances clarity and control over the web search functionality.

test(unit): skip integration test without API key

Added a condition to skip the `test_circuit_breaker_real_agentic` if the OpenAI API key is not set. This prevents unnecessary test failures in the absence of required credentials.
2026-04-01 20:38:47 +01:00
MervinPraison de069c2cbf Release v4.5.110 2026-04-01 20:26:06 +01:00
MervinPraison ff599795f8 test: Fix evaluator class name in live tests 2026-04-01 20:01:42 +01:00
9164555a7a fix: address code review feedback for mixin framework (#1256)
* fix: address code review feedback for mixin framework

- Add ChatMixin, ExecutionMixin, MemoryMixin exports to __init__.py
- Remove unused imports from memory_mixin.py (threading)
- Align achat() method signature with chat() parameters
- Ensure consistent API between sync/async variants

Addresses reviewer feedback while maintaining backward compatibility.

Co-authored-by: Mervin Praison <[email protected]>

* fix: forward new achat() params to _achat_impl and implement them

Agent-Logs-Url: https://github.com/MervinPraison/PraisonAI/sessions/03002903-d3fc-46e9-8ad7-4b1fafc70a4e

Co-authored-by: MervinPraison <[email protected]>

---------

Co-authored-by: MervinPraison <[email protected]>
Co-authored-by: Mervin Praison <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: MervinPraison <[email protected]>
2026-04-01 19:58:24 +01:00
b26c44ad90 feat: Complete Agent God Class Decomposition with Unified Mixin Framework (#1257)
* feat: Complete Agent God Class Decomposition with Unified Mixin Framework

- Complete mixin framework: ToolExecutionMixin, ChatHandlerMixin, SessionManagerMixin, ChatMixin, ExecutionMixin, MemoryMixin
- Created missing ChatHandlerMixin for chat coordination & response processing
- Created missing SessionManagerMixin for session lifecycle & state management
- Updated Agent class inheritance to follow specification order
- Maintain 100% backward API compatibility with all 34+ __init__ parameters
- Performance: Import time 59.20ms (target <200ms achieved)
- Zero breaking changes - all existing public methods preserved
- Agent class reduced from ~8,915 to 4,341 lines through proper decomposition

Resolves #1254

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Mervin Praison <[email protected]>

* fix: correct time import bug, remove raw error leakage in ChatHandlerMixin

Agent-Logs-Url: https://github.com/MervinPraison/PraisonAI/sessions/1cacd729-25d5-42df-a628-782502d1b3f1

Co-authored-by: MervinPraison <[email protected]>

* fix: handle None agent names in mixins to prevent log/session ID issues

- Fix ChatHandlerMixin to use proper None check for agent names
- Fix SessionManagerMixin to sanitize session IDs and prevent None prefixes
- Ensure consistent 'Agent' fallback across both mixins for nameless agents
- Address reviewer feedback from qodo-code-review and gemini-code-assist

Co-authored-by: Mervin Praison <[email protected]>

---------

Co-authored-by: MervinPraison <[email protected]>
Co-authored-by: Mervin Praison <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: MervinPraison <[email protected]>
2026-04-01 19:56:50 +01:00
4ee7d298c8 feat(sandbox): add SandlockSandbox for kernel-level isolation (#1255)
* feat(sandbox): add SandlockSandbox for kernel-level isolation

Implements SandlockSandbox that provides kernel-level code execution
isolation using Landlock + seccomp-bpf, addressing security gaps in
the current subprocess-based sandbox.

Security improvements:
- Landlock filesystem allowlisting (blocks /etc/passwd, SSH keys, etc.)
- seccomp-bpf syscall filtering
- Network domain/port control
- Resource limits with ~5ms overhead
- No Docker or root required

Features:
- Implements existing SandboxProtocol for drop-in compatibility
- Optional dependency with graceful fallback to SubprocessSandbox
- Comprehensive test suite with security violation testing
- Example and documentation included

Resolves: #1253

Co-authored-by: Mervin Praison <[email protected]>

* fix(sandbox): address review findings in SandlockSandbox

- Security: replace lstrip('/') with _safe_sandbox_path() using os.path.realpath()
  to block path-traversal in write_file/read_file/list_files; tighten check to
  reject paths resolving exactly to the sandbox root (directory writes)
- Correctness: replace deprecated asyncio.get_event_loop() with get_running_loop()
- DRY: extract shared execution logic into _run_sandlocked() private helper
- Dead code: remove unused self._sandbox attribute and code_file variables
- Simplify: is_available uses self._sandlock directly (import enforced in __init__)
- Tests: fix unreliable builtins.__import__ patch; update asyncio mocking to
  get_running_loop; add path-traversal tests; fix SecurityViolationError test to
  use distinct exception classes

Agent-Logs-Url: https://github.com/MervinPraison/PraisonAI/sessions/c46e5ff2-ff2d-4bc7-9bcc-5426981ef322

Co-authored-by: MervinPraison <[email protected]>

* chore: remove accidentally committed egg-info from PR

Agent-Logs-Url: https://github.com/MervinPraison/PraisonAI/sessions/c46e5ff2-ff2d-4bc7-9bcc-5426981ef322

Co-authored-by: MervinPraison <[email protected]>

---------

Co-authored-by: MervinPraison <[email protected]>
Co-authored-by: Mervin Praison <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: MervinPraison <[email protected]>
2026-04-01 19:47:27 +01:00
MervinPraison 1ae86076a9 fix(ci): strictly bind claude assistant invocation to explicit @claude mentions in issue comments 2026-04-01 19:38:27 +01:00
MervinPraison 7def9a68fa chore(ci): consolidate claude workflow entirely into claude.yml and disable all competing agents 2026-04-01 19:31:13 +01:00
dependabot[bot] 99cdf47b09 chore(deps): bump lodash (#1229)
Bumps the npm_and_yarn group with 1 update in the /src/praisonai directory: [lodash](https://github.com/lodash/lodash).


Updates `lodash` from 4.17.21 to 4.17.23
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.21...4.17.23)

---
updated-dependencies:
- dependency-name: lodash
  dependency-version: 4.17.23
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-01 19:15:23 +01:00
7bb1ca97f5 fix: add defensive wrappers for mem0 MongoDB vector store compatibility (#1251)
- Add _safe_mem0_search() wrappers in Memory and Mem0Adapter classes
- Catch TypeError: 'unexpected keyword argument vectors' gracefully
- Return empty results instead of crashing on MongoDB incompatibility
- Add informative warnings referencing upstream mem0 bug #3185
- Recommend Qdrant/Chroma as alternative vector store backends
- Maintain full backward compatibility for working configurations

Addresses upstream mem0 issue: https://github.com/mem0ai/mem0/issues/3185
Fixes: mem0 MongoDB vector store broken — signature mismatch + Atlas-only requirement

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: MervinPraison <[email protected]>
Co-authored-by: Mervin Praison <[email protected]>
2026-04-01 19:13:05 +01:00
9ba435f147 feat: enhance evaluation framework with EvalSuite, ComparisonEval, and SafetyEval (#1246)
* feat: enhance evaluation framework with EvalSuite, ComparisonEval, and SafetyEval

- Add EvalSuite orchestrator for running multiple evaluations with aggregated results
- Add ComparisonEval for side-by-side A/B testing of agent outputs across criteria
- Add SafetyEval for detecting harmful/biased/inappropriate content across 6 categories
- Update eval/__init__.py with new exports and lazy loading
- Add comprehensive unit tests for all new components (150+ test cases)
- Follow protocol-driven architecture with zero performance impact
- Maintain backward compatibility with existing eval framework

Addresses #1245

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Mervin Praison <[email protected]>

* fix(eval): resolve critical issues and add real agentic tests

- Add missing _make_llm_call method to BaseLLMGrader for ComparisonGrader and SafetyGrader
- Fix after_run() calls to pass required result parameter
- Fix winner parsing logic to prevent 'Agent B' misclassification as 'agent_a'
- Fix safety score parsing to prevent LLM override of worse category scores
- Fix EvalSuite fail_fast behavior to properly re-raise RuntimeError
- Add support for AccuracyResult avg_score in EvalSuite scoring
- Fix Python type hints compatibility (tuple[str,str] → tuple)
- Add comprehensive real agentic integration tests that call agent.start()

Addresses all critical issues identified in code reviews and fulfills
AGENTS.md Section 9.4 requirement for real agentic tests.

Co-authored-by: Mervin Praison <[email protected]>

---------

Co-authored-by: MervinPraison <[email protected]>
Co-authored-by: Mervin Praison <[email protected]>
Co-authored-by: praisonai-triage-agent[bot] <272766704+praisonai-triage-agent[bot]@users.noreply.github.com>
2026-04-01 19:11:52 +01:00
MervinPraison 8582562e45 docs: auto-update api.md [skip ci] 2026-04-01 18:09:14 +00:00
Mervin Praison 76c1248e38 Merge pull request #1252 from MervinPraison/claude/issue-1250-20260401-1630
feat: move multi-backend storage adapters to wrapper following AGENTS.md
2026-04-01 19:08:58 +01:00
copilot-swe-agent[bot]andMervinPraison 4ca5867075 fix: address security and correctness issues in storage adapters
- PostgreSQL: validate table name against safe identifier regex to
  prevent SQL injection via user-controlled table parameter
- MongoDB: escape regex metacharacters in list_keys prefix to prevent
  ReDoS / unexpected pattern matching
- MongoDB: use $setOnInsert for created_at so it is preserved on
  update (was being overwritten on every save)
- DynamoDB: replace raw string FilterExpression with proper Boto3
  Attr().begins_with() condition in list_keys
- DynamoDB: remove redundant boto3 import in _create_table (already
  imported in _get_table)

Agent-Logs-Url: https://github.com/MervinPraison/PraisonAI/sessions/c012c607-294a-4cef-864d-91a2bccca2dd

Co-authored-by: MervinPraison <[email protected]>
2026-04-01 17:37:40 +00:00
MervinPraison ce7d9815aa fix: implement proper lazy loading for storage adapters
- Remove eager module-level imports of heavy backends (Redis/MongoDB/PostgreSQL/DynamoDB)
- Implement lazy loading in get_backend() function using getattr() only when needed
- Update __all__ exports to only include lightweight backends
- Add module-level __getattr__ for backward compatibility
- Follow praisonaiagents/db pattern for proper separation of core vs wrapper

Fixes critical architectural violation where heavy wrapper dependencies
were being imported at module level, breaking the lazy loading design.

Core SDK imports now work without wrapper package (< 50ms import time).

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Mervin Praison <[email protected]>
2026-04-01 17:27:48 +00:00
MervinPraison 6a531ac1da feat(ci): unify claude evaluation prompts to process ALL bot reviewers 2026-04-01 18:15:06 +01:00
MervinPraison cc6116b888 feat(ci): enhance claude-after-gemini prompt for strict issue fixing 2026-04-01 18:13:22 +01:00
MervinPraison d933eebeaf feat(ci): auto-trigger Claude after Gemini code assist 2026-04-01 18:08:45 +01:00
MervinPraison 2c683af1cd fix(ci): trigger review chain on triage-agent PRs 2026-04-01 18:03:39 +01:00
MervinPraison a1b6989840 docs(workflows): codify manager-agent philosophy for issue triage 2026-04-01 17:48:15 +01:00
MervinPraisonandMervin Praison 98a878673a feat: move multi-backend storage adapters to wrapper following AGENTS.md
- Move Redis, MongoDB, PostgreSQL, and DynamoDB storage adapters from core SDK to wrapper
- Implement lazy proxy pattern following praisonaiagents.db model
- Add optional dependencies [redis], [mongodb], [postgresql], [dynamodb] to wrapper
- Core SDK now protocol-driven only, heavy implementations in wrapper
- Resolves architectural violations from PRs #1241, #1247, #1248

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Mervin Praison <[email protected]>
2026-04-01 16:39:08 +00:00
MervinPraison cec46053ab fix(ci): wire gh_token for workflow cascading and allowlist triage bot 2026-04-01 17:12:25 +01:00
MervinPraison ad7445c528 feat(ci): mandate AGENTS.md reading in gemini code modification prompts 2026-04-01 11:56:10 +01:00
MervinPraison 3e2909b926 feat(ci): mandate PR creation and AGENTS.md reading in claude-code-action prompt 2026-04-01 11:54:54 +01:00
MervinPraison ad32470de4 fix(ci): wire claude pro oauth token into triage workflows 2026-04-01 10:38:28 +01:00
MervinPraison 5dd9bdb96f chore: migrate github actions to use dedicated github app for rate limit bypass 2026-04-01 10:06:45 +01:00
MervinPraison 29b0a6f02e docs: auto-update feature parity trackers [skip ci] 2026-04-01 08:34:46 +00:00
MervinPraison 7a9788c311 fix(qa): resolve missing ephemeral contextmanager and test_mixin_inheritance following god class decomposition 2026-04-01 09:34:29 +01:00
MervinPraison 055d9f5d88 chore: add id-token permission to claude-issue-triage workflow and document OIDC requirements in review-chain instructions 2026-04-01 09:34:29 +01:00
MervinPraison b27ae3a79a feat: extract agent god class into clean chat, execution, memory, and tool mixins 2026-04-01 09:34:29 +01:00
Mervin Praison d0a4796742 Merge pull request #1239 from Sundiver1/fix/pin-axios-supply-chain
Fix: pin axios to 1.8.4 to prevent supply chain compromise
2026-04-01 09:09:38 +01:00
Chris Braley a3ce0f69e3 fix: pin axios to 1.8.4 to avoid supply chain compromise
Compromised versions 1.14.1 and 0.30.4 were removed from npm registry
but semver ranges (^1.7.9) could resolve to malicious versions if
they're re-released or exist in alternate registries.

Pinning to exact version 1.8.4 prevents this attack vector entirely.
2026-04-01 01:55:33 -05:00
Mervin Praison 19929dd9de Merge pull request #1238 from MervinPraison/fix/gha-claude-oidc-token
fix(gha): Add id-token write permission and switch to GH_TOKEN for Claude actions
2026-04-01 07:36:29 +01:00
MervinPraison 36c2e76ca4 fix(gha): Add id-token write permission and switch to GH_TOKEN for Claude actions
Fixes OIDC token fetch failure and 401 Bad Credentials errors in claude.yml and claude-issue-triage.yml.
2026-04-01 07:36:24 +01:00
Mervin Praison a0e4a765ff Merge pull request #1237 from MervinPraison/fix/dynamic-interactive-runtime
feat: Dynamically load InteractiveRuntime for ACP/LSP in YAML workflows
2026-04-01 07:26:38 +01:00
MervinPraison 18a3d26620 feat: Dynamically load InteractiveRuntime for ACP/LSP in YAML workflows 2026-04-01 07:26:33 +01:00
Mervin Praison cbec55cf44 fix: Update valid inputs for claude-code-action in issue triage (#1236)
fix: Update valid inputs for claude-code-action in issue triage
2026-04-01 07:22:32 +01:00
MervinPraison f96eebb5e8 fix: Update valid inputs for claude-code-action in issue triage
The base claude-code-action does not accept 'prompt_file' or 'install_github_mcp'.
This routes the prompt properly through 'direct_prompt' using GitHub step outputs.
2026-04-01 07:22:19 +01:00
Mervin Praison 6fa8eebab1 fix: Cleanup dead acp_enabled and lsp_enabled code from YAML workflow generator (#1234)
fix: Cleanup dead acp_enabled and lsp_enabled code from YAML workflow generator
2026-04-01 07:15:46 +01:00
MervinPraison 9702a2a99c fix: Cleanup dead acp_enabled and lsp_enabled code from YAML workflow generator
Closes #1233
Removes dead code path to ensure alignment with AgentTeam __init__ signature.
2026-04-01 07:15:21 +01:00
MervinPraison 969c21f617 Release v4.5.109 2026-04-01 07:03:13 +01:00
MervinPraison 8b5b67852a docs(README): fix list formatting for TAVILY_API_KEY instruction
Adjusted the formatting of the TAVILY_API_KEY instruction for consistency.
2026-03-31 23:30:30 +01:00
MervinPraison 019ecea1a4 docs(README): add environment variable setup instruction
Added a line to specify the export command for setting the TAVILY_API_KEY. This addition improves clarity for users configuring the environment.
2026-03-31 23:30:03 +01:00
MervinPraison fab53bf095 Release v4.5.108 2026-03-31 23:25:49 +01:00
MervinPraison d6bcd522ed docs: rename AgentClaw to PraisonAI Claw in README 2026-03-31 23:14:09 +01:00
MervinPraison 8769a3bdb8 Release v4.5.107 2026-03-31 23:01:40 +01:00
MervinPraison bfda2ff1db Merge branch 'main' of https://github.com/MervinPraison/PraisonAI 2026-03-31 23:00:00 +01:00
MervinPraison 0a7d4187ad feat(docs): add PraisonAI UI installation instructions and details
Updated README.md to include a new section for the PraisonAI UI,
providing installation instructions and a brief description.
Bumped version numbers in pyproject.toml and lock files to
reflect changes and dependency updates.
2026-03-31 22:59:52 +01:00
MervinPraison b0222c4fae docs: auto-update api.md [skip ci] 2026-03-31 21:55:00 +00:00
MervinPraison 1c901be114 Release v4.5.106 2026-03-31 22:54:43 +01:00
MervinPraison 534594103d Release v4.5.105 2026-03-31 22:34:12 +01:00
MervinPraison 17d7ddd0f7 Release v4.5.104 2026-03-31 22:11:57 +01:00
MervinPraison c546d2c2c9 chore(.github): update agentflow.gif with larger file size for better quality 2026-03-31 22:06:10 +01:00
MervinPraison 13267e5325 Release v4.5.103 2026-03-31 22:04:13 +01:00
MervinPraison f188ae1ff9 Release v4.5.102 2026-03-31 21:37:29 +01:00
MervinPraison 17ca3f8f48 Release v4.5.101 2026-03-31 21:16:53 +01:00
MervinPraison ed76058630 Release v4.5.100 2026-03-31 19:31:04 +01:00
MervinPraison 9b50b4069f feat(PraisonAI): update version and enhance agent memory functionality
Updated package version to 1.5.99 and introduced new memory handling
features in PraisonAI components. Added configuration for session
tracking in memory save. Included additional tests for agent and task
components to ensure correct functionality and integration.
2026-03-31 19:12:12 +01:00
MervinPraison 9ad41a8ec5 Release v4.5.98 2026-03-31 18:54:52 +01:00
MervinPraison 3f77e93840 Release v4.5.96 2026-03-31 18:46:49 +01:00
MervinPraison 06eb6b197c Release v4.5.97 2026-03-31 16:23:39 +01:00
MervinPraison d476379f45 chore: bump praisonaiagents to 1.5.95 2026-03-31 16:23:06 +01:00
MervinPraison d1034adc19 refactor: harden input validation and access controls 2026-03-31 16:20:54 +01:00
MervinPraison ee8d0cf4c3 chore(migration): remove outdated MIGRATION.md file
Deleted the deprecated migration guide as it is no longer relevant.
2026-03-31 16:15:17 +01:00
MervinPraison acad479b19 chore(images): move assets to .github folder and update paths
Relocated image assets from the public directory to the .github/images directory. Updated references in README files to reflect the new asset locations. Added a new GIF asset for showcasing command execution. Total of 14 files changed with 16 insertions and 8 deletions.
2026-03-31 16:13:35 +01:00
MervinPraison 1eb22d74e9 Release v4.5.96 2026-03-31 15:47:09 +01:00
MervinPraison 381c7448ea Release v4.5.95 2026-03-31 15:39:40 +01:00
MervinPraison 13c984d1aa Release v4.5.94 2026-03-31 15:21:59 +01:00
MervinPraison b04513493e docs: auto-update api.md [skip ci] 2026-03-31 13:52:11 +00:00
MervinPraison 3a209d7c36 Release v4.5.93 2026-03-31 14:51:48 +01:00
MervinPraison eb15d66e96 ci: add architecture validation guardrails to Claude agent prompt
- STEP 0: Set git identity to MervinPraison for all commits
- STEP 2: Mandatory bloat validation checklist before writing code
- Checks: protocol-driven design, no heavy impls in core SDK, no duplication,
  proper Agent inheritance, lazy imports, no agent.py growth, no name collisions
- If checks fail: close issue with explanation instead of creating bad PRs
2026-03-31 13:18:22 +01:00
MervinPraison 54ddbaf298 ci: use PAT_TOKEN for claude issue triage so comments appear as MervinPraison 2026-03-31 12:55:03 +01:00
MervinPraison 18b7dc1687 ci: use PAT_TOKEN for claude action so PRs open as MervinPraison 2026-03-31 12:41:08 +01:00
MervinPraison 10869d7570 ci: fix duplicate claude action runs on issue labeled events 2026-03-31 12:38:45 +01:00
MervinPraison c796f75b41 update 2026-03-31 12:24:09 +01:00
MervinPraison 79cda2604b Release v4.5.90 2026-03-31 11:07:00 +01:00
MervinPraison 7659748515 chore: bump praisonaiagents to 1.5.91 2026-03-31 11:04:38 +01:00
MervinPraison aa092c2c3f chore: bump praisonaiagents to 1.5.90 2026-03-31 11:00:34 +01:00
MervinPraison dc69cbc121 refactor: harden input validation and query parameterization
- Strengthen attribute access guards in code execution sandbox
- Parameterize SQL IN clauses in data layer
- Add URL scheme validation for API base URLs
- Use plain string matching instead of regex for tool search
2026-03-31 10:59:47 +01:00
MervinPraison 60121929d0 docs: auto-update api.md [skip ci] 2026-03-31 09:15:54 +00:00
Mervin Praison 6646dd1a4c refactor: SDK Architecture - Centralize Logging and Retry Logic (#1212)
Merges centralized logging (_logging.py, 152 files migrated) and resilience utility (utils/resilience.py). Also fixes CI/CD workflows and test fixtures.

Closes #1131 #1132
2026-03-31 10:15:32 +01:00
MervinPraison ba3a3c3ee0 fix(ci): optimize CI/CD workflows and harden test fixtures
- Remove unittest.yml (517-line debug file, always failed exit 5)
- Fix test-core.yml: deprecated codecov 'file:' -> 'files:' input
- Fix test-optimized.yml: move secrets from inline shell expressions
  to env: blocks to resolve linter context access warnings
- Fix test_serve_integration.py: replace 6x hardcoded /Users/praison paths
  with dynamic pathlib resolution (portable on any CI runner)
- Fix test_tracker_complex_tasks.py: DEFAULT_TOOLS -> AUTONOMY_DEFAULT_TOOLS
  (symbol was renamed in tracker.py, causing ImportError in CI)

Resolves GitHub Actions lint IDs:
7c7e1668 1d881864 aa30b182 a28bb9f7 ca2c8cc1 132d4548
a2735061 d3729ccb 333ae3f5 f3aca47c 7353e2c3 6d3216de
2026-03-31 09:51:45 +01:00
MervinPraison b965bb1011 Release v4.5.89 2026-03-31 09:45:58 +01:00
MervinPraison 4d13ab4af7 fix(logging): improve logger level settings across multiple modules
Updated logger level settings to use consistent DEBUG and WARNING levels
based on the verbosity of the application. This enhances logging clarity
and ensures that third-party loggers are set to WARNING by default.
Adjusted imports to maintain consistent logging behavior across various
modules for better maintainability. Additionally, bumped version in
pyproject.toml to 1.5.89.
2026-03-31 09:45:22 +01:00
MervinPraison 84c4d221a2 refactor: centralize logging and retry logic (#1131, #1132) 2026-03-31 08:59:15 +01:00
MervinPraison 64ae40e369 docs: auto-update feature parity trackers [skip ci] 2026-03-31 07:02:09 +00:00
Mervin Praison 0f5849b734 Merge pull request #1184 from MervinPraison/claude/remaining-thread-safety-fixes
Tool registry thread safety - MERGEABLE, covers gap not addressed by #1175/#1176. Unit tests: 4473 passed. Integration: 294 passed.
2026-03-31 08:01:58 +01:00
Mervin Praison 3a2a2f8592 Merge pull request #1185 from MervinPraison/claude/fix-agent-type-hints-20260330
Type hints PR - MERGEABLE, low risk, improves IDE support. Unit tests: 4473 passed. Integration: 294 passed.
2026-03-31 08:01:49 +01:00
github-actions[bot]andMervin Praison d143cce2f9 fix: Add comprehensive type hints to Agent class public methods
Fixes identified issues from PR #1179:
- Add type hints to chat(), run(), start(), execute_tool(), execute() methods
- Fix ephemeral() return type to Generator[None, None, None] for context manager
- Add Optional[str] return types for methods that can return None (chat, run, execute)
- Add type hints to all property getters and setters
- Add type annotations to **kwargs parameters

This resolves type checker warnings and improves IDE autocompletion support.

Co-authored-by: Mervin Praison <[email protected]>
2026-03-30 20:30:52 +00:00
github-actions[bot]andMervin Praison 9bb149a244 fix: improve thread safety in tool registry
- Use thread-safe registry.unregister() in remove_tool()
- Use thread-safe registry.list_tools() in list_tools()
- Add double-checked locking to get_registry() singleton
- Prevents race conditions in multi-agent deployments

Related to #1167 and closed PR #1182

Co-authored-by: Mervin Praison <[email protected]>
2026-03-30 20:28:22 +00:00
329 changed files with 15364 additions and 7566 deletions

No files matched your search

@@ -5,6 +5,9 @@ inputs:
anthropic_api_key:
description: "Anthropic API key"
required: false
claude_code_oauth_token:
description: "Claude Code OAuth Token for Claude Pro"
required: false
github_token:
description: "GitHub token for Claude to operate with"
required: false
@@ -212,6 +215,13 @@ runs:
- Documentation updates
- Testing and deployment
CRITICAL INSTRUCTION: If your task involves modifying codebase files to add a feature or fix a bug:
1. ALWAYS create a new git branch appropriately named (e.g. \`feature/issue-<number>\`).
2. MANDATORY: Before writing any code, you MUST carefully read "src/praisonai-agents/AGENTS.md" to understand this repository's extremely specific Architecture, Protocol-First design rules, and Agent-Centric Philosophy.
3. Make your necessary code changes honoring the rules in AGENTS.md.
4. Commit your changes and push the branch to the remote repository.
5. Use the GitHub CLI (\`gh pr create --title "..." --body "Fixes #<number>"\`) to open a Pull Request containing your work.
Respond naturally and helpfully to the user's request using the available tools.
EOF
@@ -253,4 +263,5 @@ runs:
echo "✅ Claude Code execution completed"
env:
ANTHROPIC_API_KEY: ${{ inputs.anthropic_api_key }}
CLAUDE_CODE_OAUTH_TOKEN: ${{ inputs.claude_code_oauth_token }}
GITHUB_TOKEN: ${{ inputs.github_token }}
@@ -6,8 +6,8 @@ inputs:
description: "Timeout in minutes for execution"
required: false
default: "5"
anthropic_api_key:
description: "Anthropic API key"
claude_code_oauth_token:
description: "Claude Code OAuth token for Pro subscription access"
required: true
github_token:
description: "GitHub token with repo and issues permissions"
@@ -21,7 +21,8 @@ runs:
with:
fetch-depth: 0
- name: Create prompt file
- name: Create prompt
id: generate_prompt
shell: bash
run: |
mkdir -p /tmp/claude-prompts
@@ -75,13 +76,16 @@ runs:
- Your ONLY action should be to apply labels using mcp__github__update_issue
- It's okay to not add any labels if none are clearly applicable
EOF
echo "PROMPT<<DELIMITER" >> $GITHUB_OUTPUT
cat /tmp/claude-prompts/claude-issue-triage-prompt.txt >> $GITHUB_OUTPUT
echo "DELIMITER" >> $GITHUB_OUTPUT
- name: Run Claude Code
uses: ./.github/actions/claude-code-action
with:
prompt_file: /tmp/claude-prompts/claude-issue-triage-prompt.txt
direct_prompt: ${{ steps.generate_prompt.outputs.PROMPT }}
allowed_tools: "Bash(gh label list),mcp__github__get_issue,mcp__github__get_issue_comments,mcp__github__update_issue,mcp__github__search_issues,mcp__github__list_issues"
install_github_mcp: "true"
timeout_minutes: ${{ inputs.timeout_minutes }}
anthropic_api_key: ${{ inputs.anthropic_api_key }}
claude_code_oauth_token: ${{ inputs.claude_code_oauth_token }}
github_token: ${{ inputs.github_token }}
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 MiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 109 KiB

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 285 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 429 B

After

Width:  |  Height:  |  Size: 429 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 872 B

After

Width:  |  Height:  |  Size: 872 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 168 KiB

After

Width:  |  Height:  |  Size: 168 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 167 KiB

After

Width:  |  Height:  |  Size: 167 KiB

+4 -3
View File
@@ -1,8 +1,9 @@
name: Auto Issue Comment
on:
issues:
types: [opened]
workflow_dispatch:
# issues:
# types: [opened]
jobs:
# Trigger Claude by adding the 'claude' label (only if not already labeled)
@@ -19,7 +20,7 @@ jobs:
- name: Add claude label to trigger analysis
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GH_TOKEN }}
script: |
// Check if 'claude' label already exists on this issue
const labels = context.payload.issue.labels.map(l => l.name);
+8 -4
View File
@@ -31,7 +31,7 @@ jobs:
- name: Post Copilot review request (as user via PAT)
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GH_TOKEN }}
script: |
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
@@ -66,7 +66,7 @@ jobs:
- name: Post Copilot review request (as user via PAT)
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GH_TOKEN }}
script: |
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
@@ -97,7 +97,11 @@ jobs:
if: |
github.event_name == 'pull_request' &&
github.event.action == 'opened' &&
github.event.pull_request.user.login == 'github-actions[bot]'
(
github.event.pull_request.user.login == 'github-actions[bot]' ||
github.event.pull_request.user.login == 'praisonai-triage-agent[bot]' ||
github.event.pull_request.user.type == 'Bot'
)
runs-on: ubuntu-latest
permissions:
pull-requests: write
@@ -105,7 +109,7 @@ jobs:
- name: Trigger CodeRabbit, Qodo, and Gemini reviews
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GH_TOKEN }}
script: |
const pr = context.payload.pull_request.number;
const owner = context.repo.owner;
@@ -5,17 +5,16 @@ on:
pull_request_review:
types: [submitted]
# Future: re-enable issue_comment trigger for Gemini→Claude chain
# issue_comment:
# types: [created]
issue_comment:
types: [created]
jobs:
# Trigger Claude after Copilot finishes on a PR — Claude is the FINAL reviewer
# Claude reads ALL previous reviews (Qodo, Coderabbit, Copilot) and fixes any valid issues
claude-final-review:
if: |
github.event_name == 'pull_request_review' &&
github.event.review.user.login == 'copilot-pull-request-reviewer[bot]'
(github.event_name == 'pull_request_review' && contains(github.event.review.user.login, 'copilot')) ||
(github.event_name == 'issue_comment' && contains(github.event.comment.user.login, 'copilot'))
runs-on: ubuntu-latest
permissions:
pull-requests: write
@@ -23,33 +22,37 @@ jobs:
- name: Post Claude final review + fix request
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '@claude You are the FINAL architecture reviewer. Read ALL comments above from Qodo, Coderabbit, and Copilot carefully before responding.\n\n**Phase 1: Review per AGENTS.md**\n1. Protocol-driven: heavy code in wrapper, not core SDK?\n2. Backward compatible: no public API removed without deprecation?\n3. Performance: no hot-path regressions, lazy imports for optional deps?\n4. DRY: no duplication, reuses existing abstractions?\n5. Async-safe and multi-agent safe?\n\n**Phase 2: Fix valid issues from other reviewers**\n6. Read Qodo, Coderabbit, and Copilot reviews above\n7. For each VALID suggestion they raised: implement the fix\n8. Push all fixes to THIS branch (do NOT create a new PR)\n9. Comment a summary of what you fixed and what you intentionally skipped (with reasoning)\n\n**Phase 3: Final verdict**\n10. If all issues are resolved and tests pass, approve the PR\n11. If blocking issues remain, request changes with clear action items'
body: '@claude You are the FINAL architecture reviewer. Read ALL comments above from Gemini, Qodo, CodeRabbit, and Copilot carefully before responding.\n\n**Phase 1: Review per AGENTS.md**\n1. Protocol-driven: check heavy implementations vs core SDK\n2. Backward compatible: ensure zero feature regressions\n3. Performance: no hot-path regressions\n\n**Phase 2: FIX Valid Issues**\n4. For any VALID bugs or architectural flaws found by Gemini, CodeRabbit, Qodo, Copilot, or any other reviewer: implement the fix\n5. Push all code fixes directly to THIS branch (do NOT create a new PR)\n6. Comment a summary of exact files modified and what you skipped\n\n**Phase 3: Final Verdict**\n7. If all issues are resolved, approve the PR / close the Issue\n8. If blocking issues remain, request changes / leave clear action items'
})
# Future: Trigger Claude after Gemini finishes on an Issue (commented out)
# claude-after-gemini-on-issue:
# if: |
# github.event_name == 'issue_comment' &&
# !github.event.issue.pull_request &&
# github.event.comment.user.login == 'gemini-code-assist[bot]'
# runs-on: ubuntu-latest
# permissions:
# issues: write
# steps:
# - name: Post Claude analysis request (final reviewer)
# uses: actions/github-script@v7
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# script: |
# github.rest.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: '@claude You are the lead engineer. Read Gemini\'s analysis above first.\n\nAnalyze this issue and implement a fix following AGENTS.md:\n1. Ensure backward compatibility — no features removed\n2. Zero performance regression on hot paths\n3. Minimal, focused changes only\n4. Run tests to verify the fix\n5. Create a PR with your changes using gh'
# })
# Trigger Claude after Gemini finishes on an Issue or PR
claude-after-gemini:
if: |
github.event_name == 'issue_comment' &&
(
github.event.comment.user.login == 'gemini-code-assist[bot]' ||
contains(github.event.comment.body, 'Review completed by Gemini CLI') ||
contains(github.event.comment.body, 'The fix is ready for review. Please test')
)
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Post Claude analysis request (final reviewer)
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '@claude You are the Lead Engineer. Read ALL analysis and reviews above carefully (Gemini, CodeRabbit, Qodo, Copilot, etc).\n\n**Phase 1: Review per AGENTS.md**\n1. Protocol-driven: check heavy implementations vs core SDK\n2. Backward compatible: ensure zero feature regressions\n3. Performance: no hot-path regressions\n\n**Phase 2: FIX Valid Issues**\n4. For any VALID bugs or architectural flaws found by Gemini, CodeRabbit, Qodo, Copilot, or any other reviewer: implement the fix\n5. Push all code fixes directly to THIS branch (do NOT create a new PR)\n6. Comment a summary of exact files modified and what you skipped\n\n**Phase 3: Final Verdict**\n7. If all issues are resolved, approve the PR / close the Issue\n8. If blocking issues remain, request changes / leave clear action items'
})
+13 -4
View File
@@ -2,8 +2,9 @@ name: Claude Issue Triage
description: "Automatically triage GitHub issues using Claude Code"
on:
issues:
types: [opened]
workflow_dispatch:
# issues:
# types: [opened]
jobs:
triage-issue:
@@ -12,12 +13,20 @@ jobs:
permissions:
contents: read
issues: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Generate GitHub App Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.CLAUDE_APP_ID }}
private-key: ${{ secrets.CLAUDE_APP_PRIVATE_KEY }}
- name: Run Claude Issue Triage
uses: ./.github/actions/claude-issue-triage-action
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
github_token: ${{ steps.app-token.outputs.token }}
+46 -9
View File
@@ -6,7 +6,7 @@ on:
pull_request_review_comment:
types: [created]
issues:
types: [assigned, labeled]
types: [assigned, labeled, opened]
pull_request_review:
types: [submitted]
@@ -15,9 +15,12 @@ jobs:
# Allow: human users, github-actions[bot] (auto-comments/labels)
# Block: dependabot, cursor, renovate, other bots
if: |
(github.event.action != 'labeled' || github.event.label.name == 'claude') &&
(github.event_name != 'issue_comment' || contains(github.event.comment.body, '@claude')) &&
(
!contains(github.actor, '[bot]') ||
github.actor == 'github-actions[bot]'
github.actor == 'github-actions[bot]' ||
github.actor == 'praisonai-triage-agent[bot]'
) &&
github.actor != 'dependabot[bot]' &&
github.actor != 'cursor[bot]' &&
@@ -28,25 +31,59 @@ jobs:
pull-requests: write
issues: write
actions: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate GitHub App Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.CLAUDE_APP_ID }}
private-key: ${{ secrets.CLAUDE_APP_PRIVATE_KEY }}
- uses: anthropics/claude-code-action@beta
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
github_token: ${{ steps.app-token.outputs.token }}
trigger_phrase: "@claude"
label_trigger: "claude"
allowed_non_write_users: "*"
direct_prompt: |
Analyze this issue and implement a fix following AGENTS.md:
1. Read AGENTS.md for repo guidelines
2. Search the codebase and identify the root cause
3. Create a fix branch and implement a minimal, focused fix
4. Run tests to verify
5. Commit, push, and create a PR using `gh pr create`
You are working on the PraisonAI SDK. Follow AGENTS.md strictly.
STEP 0 — SETUP GIT IDENTITY:
git config user.name "MervinPraison"
git config user.email "[email protected]"
STEP 1 — READ GUIDELINES:
Read AGENTS.md to understand the architecture rules.
STEP 2 — ARCHITECTURE VALIDATION (MANDATORY before writing code):
Before implementing anything, answer these questions:
- Does this add heavy implementations to the core SDK (praisonaiagents)? If YES → move it to the wrapper (praisonai) or make it a plugin.
- Does it duplicate existing functionality? Check if Agent already supports this via existing params (reflection, planning, tools, hooks, memory).
- Does it inherit from Agent properly? New agent types MUST inherit Agent, not wrap it with composition.
- Does it add new dependencies? Only optional deps allowed, must be lazy-imported.
- Will agent.py grow larger? If the change adds >50 lines to agent.py, find a way to extract instead.
- Is there a name collision with existing exports in __init__.py?
If ANY of these checks fail, add a comment to the issue explaining why and close it. Do NOT create a PR.
STEP 3 — IMPLEMENT:
- Create a fix branch and implement a minimal, focused fix
- Follow protocol-driven design: protocols in core SDK, heavy implementations in wrapper
- Keep changes small and backward-compatible
STEP 4 — TEST:
- Run: cd src/praisonai-agents && PYTHONPATH=. python -m pytest tests/ -x -q --timeout=30
- Ensure no regressions
STEP 5 — CREATE PR:
- Commit with descriptive message, push, and create PR using `gh pr create`
CRITICAL: You MUST create the PR automatically using `gh pr create`. Do NOT just provide a link.
allowed_tools: |
Bash(git:*)
@@ -1,8 +1,10 @@
name: Gemini Automated Issue Triage
# on:
# issue_comment:
# types: [created]
on:
issue_comment:
types: [created]
workflow_dispatch:
jobs:
triage-issue:
+5 -3
View File
@@ -2,8 +2,8 @@ name: Gemini Issue Review
on:
workflow_dispatch:
issue_comment:
types: [created]
# issue_comment:
# types: [created]
permissions:
contents: write
@@ -40,7 +40,7 @@ jobs:
- name: Set up Git
run: |
git config --local user.email "praison.ms@gmail.com"
git config --local user.email "[email protected].com"
git config --local user.name "MervinPraison"
- name: Get issue data
@@ -104,6 +104,8 @@ jobs:
- Search codebase for related files using `glob`, `search_file_content`, `list_directory`
**STEP 2: If Code Changes Are Needed**
MANDATORY FIRST STEP: Before writing any code, you MUST use `read_file` to carefully read "src/praisonai-agents/AGENTS.md". You must honor this repository's extremely specific Architecture, Protocol-First design rules, and Agent-Centric Philosophy!
Create a new branch with 'gemini/' prefix:
- Use: `git checkout -b gemini/issue-${ISSUE_NUMBER}-description`
- Example: `git checkout -b gemini/issue-123-fix-sequential-tools`
+4 -2
View File
@@ -1,8 +1,8 @@
name: Gemini PR Review
on:
issue_comment:
types: [created]
# issue_comment:
# types: [created]
workflow_dispatch:
inputs:
pr_number:
@@ -159,6 +159,8 @@ jobs:
- Analyze the code changes thoroughly
**STEP 2: If Code Improvements Are Needed**
MANDATORY FIRST STEP: Before writing any code, you MUST use `read_file` to carefully read "src/praisonai-agents/AGENTS.md". You must honor this repository's extremely specific Architecture, Protocol-First design rules, and Agent-Centric Philosophy!
**IMPORTANT:** DO NOT create a new branch! Work on the EXISTING PR branch.
- Use: `git fetch origin` to get latest changes
- Get PR branch name: `gh pr view ${PR_NUMBER} --json headRefName`
+2 -2
View File
@@ -52,7 +52,7 @@ jobs:
- name: Sync with upstream
run: |
git config --global user.name "MervinPraison"
git config --global user.email "praison.ms@gmail.com"
git config --global user.email "[email protected].com"
# Add upstream remote
git remote add upstream https://github.com/MervinPraison/PraisonAI.git
@@ -474,7 +474,7 @@ jobs:
- name: Create tag at commit
run: |
git config --global user.name "MervinPraison"
git config --global user.email "praison.ms@gmail.com"
git config --global user.email "[email protected].com"
# Remove tag if it exists locally
git tag -d ${{ github.event.inputs.tag }} || true
+3 -2
View File
@@ -64,9 +64,10 @@ jobs:
|| echo "Some integration tests failed"
- name: Upload coverage to Codecov
if: always()
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: src/praisonai/coverage.xml
token: ${{ secrets.CODECOV_TOKEN || '' }}
files: src/praisonai/coverage.xml
flags: core-tests
fail_ci_if_error: false
+14 -6
View File
@@ -157,8 +157,8 @@ jobs:
if: matrix.python-version == '3.11'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: src/praisonai/coverage.xml
token: ${{ secrets.CODECOV_TOKEN || '' }}
files: src/praisonai/coverage.xml
flags: main-tests
fail_ci_if_error: false
@@ -301,8 +301,10 @@ jobs:
steps:
- name: Check if Google key is available
id: check-key
env:
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
run: |
if [ -n "${{ secrets.GOOGLE_API_KEY }}" ]; then
if [ -n "$GOOGLE_API_KEY" ]; then
echo "has_key=true" >> $GITHUB_OUTPUT
else
echo "has_key=false" >> $GITHUB_OUTPUT
@@ -356,8 +358,10 @@ jobs:
steps:
- name: Check if Groq key is available
id: check-key
env:
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
run: |
if [ -n "${{ secrets.GROQ_API_KEY }}" ]; then
if [ -n "$GROQ_API_KEY" ]; then
echo "has_key=true" >> $GITHUB_OUTPUT
else
echo "has_key=false" >> $GITHUB_OUTPUT
@@ -411,8 +415,10 @@ jobs:
steps:
- name: Check if xAI key is available
id: check-key
env:
XAI_API_KEY: ${{ secrets.XAI_API_KEY }}
run: |
if [ -n "${{ secrets.XAI_API_KEY }}" ]; then
if [ -n "$XAI_API_KEY" ]; then
echo "has_key=true" >> $GITHUB_OUTPUT
else
echo "has_key=false" >> $GITHUB_OUTPUT
@@ -466,8 +472,10 @@ jobs:
steps:
- name: Check if Cohere key is available
id: check-key
env:
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
run: |
if [ -n "${{ secrets.COHERE_API_KEY }}" ]; then
if [ -n "$COHERE_API_KEY" ]; then
echo "has_key=true" >> $GITHUB_OUTPUT
else
echo "has_key=false" >> $GITHUB_OUTPUT
+2 -2
View File
@@ -53,5 +53,5 @@ jobs:
commit_message: "docs: auto-update api.md [skip ci]"
file_pattern: 'api.md'
commit_user_name: "MervinPraison"
commit_user_email: "praison.ms@gmail.com"
commit_author: "MervinPraison <praison.ms@gmail.com>"
commit_user_email: "[email protected].com"
commit_author: "MervinPraison <[email protected].com>"
+3 -3
View File
@@ -69,15 +69,15 @@ jobs:
commit_message: "docs: auto-update documentation parity trackers [skip ci]"
file_pattern: 'src/praisonai-agents/DOCS_PARITY.md src/praisonai-ts/DOCS_PARITY.md src/praisonai-rust/DOCS_PARITY.md'
commit_user_name: "MervinPraison"
commit_user_email: "praison.ms@gmail.com"
commit_author: "MervinPraison <praison.ms@gmail.com>"
commit_user_email: "[email protected].com"
commit_author: "MervinPraison <[email protected].com>"
- name: Commit and push changes to PraisonAIDocs
if: steps.check_changes.outputs.changes == 'true' && steps.checkout_docs.outcome == 'success'
run: |
cd PraisonAIDocs
git config user.name "MervinPraison"
git config user.email "praison.ms@gmail.com"
git config user.email "[email protected].com"
git add docs/features/DOCS_PARITY.md docs/js/DOCS_PARITY.md docs/rust/DOCS_PARITY.md
git diff --staged --quiet || git commit -m "docs: auto-update documentation parity trackers [skip ci]"
git push
+2 -2
View File
@@ -56,6 +56,6 @@ jobs:
commit_message: "docs: auto-update feature parity trackers [skip ci]"
file_pattern: 'src/praisonai-ts/FEATURE_PARITY_TRACKER.json src/praisonai-ts/PARITY.md src/praisonai-rust/FEATURE_PARITY_TRACKER.json src/praisonai-rust/PARITY.md'
commit_user_name: "MervinPraison"
commit_user_email: "praison.ms@gmail.com"
commit_author: "MervinPraison <praison.ms@gmail.com>"
commit_user_email: "[email protected].com"
commit_author: "MervinPraison <[email protected].com>"
+2 -1
View File
@@ -96,4 +96,5 @@ Cargo.lock
.windsurf
.agent
src/praisonai/build
src/praisonai/build*.egg-info/
src/praisonai/PraisonAI.egg-info/
-238
View File
@@ -1,238 +0,0 @@
# Migration Guide
This guide documents breaking changes and deprecations in PraisonAI, with migration instructions and timelines.
## Version Strategy
PraisonAI follows [Semantic Versioning](https://semver.org/):
- **Major versions** (e.g., 2.0.0): Breaking changes, deprecated features removed
- **Minor versions** (e.g., 1.5.0): New features, deprecations introduced
- **Patch versions** (e.g., 1.5.1): Bug fixes, no API changes
**Deprecation Timeline:**
- Features are deprecated in **minor** releases
- Deprecated features are removed in the **next major** release
- Deprecation warnings include the removal version
## Current Deprecations (v1.0.0)
### Agent Parameters → Consolidated Config Objects
**Status:** Deprecated in v1.0.0, will be removed in v2.0.0
Old standalone parameters have been consolidated into config objects for better organization and type safety.
#### ❌ Old Way (Deprecated)
```python
from praisonaiagents import Agent
agent = Agent(
name="coder",
allow_code_execution=True, # ❌ Deprecated
code_execution_mode="unsafe", # ❌ Deprecated
auto_save="my_session", # ❌ Deprecated
rate_limiter=my_limiter, # ❌ Deprecated
allow_delegation=True, # ❌ Deprecated
verification_hooks=[my_hook], # ❌ Deprecated
llm="gpt-4o-mini" # ❌ Deprecated
)
```
#### ✅ New Way (Recommended)
```python
from praisonaiagents import Agent, ExecutionConfig, MemoryConfig
from praisonaiagents.agent.autonomy import AutonomyConfig
agent = Agent(
name="coder",
model="gpt-4o-mini", # ✅ Use 'model' instead of 'llm'
handoffs=[reviewer_agent], # ✅ Use 'handoffs' instead of 'allow_delegation'
execution=ExecutionConfig(
code_execution=True,
code_mode="unsafe",
rate_limiter=my_limiter
),
memory=MemoryConfig(auto_save="my_session"),
autonomy=AutonomyConfig(verification_hooks=[my_hook])
)
```
**Migration Steps:**
1. Replace `llm=` with `model=`
2. Replace `allow_delegation=True` with `handoffs=[agent_list]`
3. Group execution-related params into `ExecutionConfig`
4. Group memory params into `MemoryConfig`
5. Group autonomy params into `AutonomyConfig`
### Task Parameters
**Status:** Deprecated in v1.0.0, will be removed in v2.0.0
#### Task Callback → on_task_complete
```python
# ❌ Old Way
task = Task(callback=my_function)
# ✅ New Way
task = Task(on_task_complete=my_function)
```
#### Task Guardrail → guardrails
```python
# ❌ Old Way
task = Task(guardrail=my_guardrail)
# ✅ New Way
task = Task(guardrails=my_guardrail)
```
### Class Renames
**Status:** Deprecated in v1.0.0, will be removed in v2.0.0
#### AutonomySignal → EscalationSignal
```python
# ❌ Old Way
from praisonaiagents.agent.autonomy import AutonomySignal
# ✅ New Way
from praisonaiagents.escalation.types import EscalationSignal
```
### Directory Structure Changes
**Status:** Deprecated in v1.0.0, will be removed in v2.0.0
#### Data Directory Migration
```bash
# Old location (deprecated)
~/.praisonai-data/
# New location (recommended)
~/.praisonai/
# Migration command
praisonai migrate-data
```
### Process Workflow → Workflow Class
**Status:** Deprecated in v1.0.0, will be removed in v2.0.0
```python
# ❌ Old Way
from praisonaiagents import process
result = process='workflow'
# ✅ New Way
from praisonaiagents import Workflow
workflow = Workflow(steps=[...])
result = workflow.start()
```
### BotOS Platform Changes
**Status:** Deprecated in v1.0.0, will be removed in v2.0.0
#### BotApprovalBackend → Platform-Specific Approvals
```python
# ❌ Old Way
from praisonai.bots._approval import BotApprovalBackend
# ✅ New Way - Use platform-specific approvals
from praisonai.bots.approval import SlackApproval, TelegramApproval, DiscordApproval
```
### LLM Module Changes
**Status:** Deprecated in v1.0.0, will be removed in v2.0.0
#### Embedding Function
```python
# ❌ Old Way
from praisonai.llm import embedding
result = embedding(text)
# ✅ New Way
from praisonai import embed
# or
from praisonai.capabilities import embed
result = embed(text) # Returns EmbeddingResult with metadata
```
## Previous Versions
### v0.9.x → v1.0.0
No breaking changes. All v0.9.x code continues to work with deprecation warnings.
## Migration Tools
### Automated Migration (Future)
We're working on automated migration tools:
```bash
# Check for deprecated usage (Future)
praisonai check-deprecations
# Auto-migrate code (Future)
praisonai migrate --from=1.0 --to=2.0
```
### Manual Migration Checklist
Before upgrading to v2.0.0:
- [ ] Update Agent constructor parameters to use config objects
- [ ] Replace `llm=` with `model=`
- [ ] Update `allow_delegation` to `handoffs`
- [ ] Update task parameters (`callback` → `on_task_complete`, `guardrail` → `guardrails`)
- [ ] Replace `AutonomySignal` with `EscalationSignal`
- [ ] Migrate data directory with `praisonai migrate-data`
- [ ] Update workflow process to Workflow class
- [ ] Replace BotApprovalBackend with platform-specific approvals
- [ ] Update embedding imports
- [ ] Run tests to ensure functionality
### Testing Your Migration
After migrating:
```bash
# Run with deprecation warnings as errors to catch any missed items
python -W error::DeprecationWarning your_script.py
# Or use pytest
python -m pytest -W error::DeprecationWarning
```
## Getting Help
- **Documentation:** Check the updated docs for new patterns
- **Examples:** See `/examples` for updated usage patterns
- **Community:** Ask questions in GitHub Discussions
- **Issues:** Report migration problems in GitHub Issues
## Contributing
When adding new deprecations:
1. Use the `@deprecated` decorator from `praisonaiagents.utils.deprecation`
2. Specify `since` and `removal` versions
3. Provide clear `alternative` guidance
4. Update this MIGRATION.md file
5. Add deprecation to the test suite
Example:
```python
from praisonaiagents.utils.deprecation import deprecated
@deprecated(
since="1.5.0",
removal="2.0.0",
alternative="use new_function() instead",
details="The new function provides better error handling"
)
def old_function():
pass
```
+81 -6
View File
@@ -1,8 +1,8 @@
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="src/praisonai/praisonai/public/logo_dark.png" />
<source media="(prefers-color-scheme: light)" srcset="src/praisonai/praisonai/public/logo_light.png" />
<img alt="PraisonAI Logo" src="src/praisonai/praisonai/public/logo_light.png" width="250" />
<source media="(prefers-color-scheme: dark)" srcset=".github/images/logo_dark.png" />
<source media="(prefers-color-scheme: light)" srcset=".github/images/logo_light.png" />
<img alt="PraisonAI Logo" src=".github/images/logo_light.png" width="250" />
</picture>
</p>
@@ -25,10 +25,40 @@
PraisonAI 🦞 — Automate and solve complex challenges with AI agent teams that plan, research, code, and deliver results to Telegram, Discord, and WhatsApp — running 24/7. A low-code, production-ready multi-agent framework with handoffs, guardrails, memory, RAG, and 100+ LLM providers, built around simplicity, customisation, and effective human-agent collaboration.
<div align="center">
<br>
<a href="https://x.com/elonmusk/status/1893870468249141688" target="_blank">
<img src="https://img.shields.io/badge/Highlighted_by_Elon_Musk-000000?style=for-the-badge&logo=x&logoColor=white" alt="Highlighted by Elon Musk" />
</a>
<p><em>"Grok 3 customer support" — <a href="https://x.com/elonmusk/status/1893870468249141688">Elon Musk quoting PraisonAI's tutorial</a></em></p>
<br>
</div>
<p align="center">
<img src="src/praisonai/praisonai/public/dashboard.png" alt="PraisonAI Dashboard" width="800" />
<img src=".github/images/dashboard.png" alt="PraisonAI Dashboard" width="800" />
</p>
<p align="center">
<img src=".github/images/agentflow.gif" alt="PraisonAI AgentFlow" width="800" />
</p>
```
██████╗ ██████╗ █████╗ ██╗███████╗ ██████╗ ███╗ ██╗ █████╗ ██╗
██╔══██╗██╔══██╗██╔══██╗██║██╔════╝██╔═══██╗████╗ ██║ ██╔══██╗██║
██████╔╝██████╔╝███████║██║███████╗██║ ██║██╔██╗ ██║ ███████║██║
██╔═══╝ ██╔══██╗██╔══██║██║╚════██║██║ ██║██║╚██╗██║ ██╔══██║██║
██║ ██║ ██║██║ ██║██║███████║╚██████╔╝██║ ╚████║ ██║ ██║██║
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝
pip install praisonai
```
<p align="center">
<img src=".github/images/latest_ai_news_and_crawl_each_url_to_find_info.gif" alt="PraisonAI command execution" width="800" />
</p>
\* `export TAVILY_API_KEY=xxxxx`
<div align="center">
<a href="https://docs.praison.ai">
<p align="center">
@@ -174,6 +204,15 @@ PraisonAI supports 100+ LLM providers through seamless integration:
</details>
<div align="center">
<a href="https://x.com/elonmusk/status/1893870468249141688" target="_blank">
<img src=".github/images/elon_musk_praisonai.png" alt="Highlighted by Elon Musk" width="600" />
</a>
<p><em>"Grok 3 customer support" — <a href="https://x.com/elonmusk/status/1893870468249141688">Elon Musk quoting PraisonAI's tutorial</a></em></p>
</div>
<br>
---
## 🚀 Quick Start
@@ -211,13 +250,27 @@ For the full framework with CLI support:
pip install praisonai
```
🦞 **AgentClaw** — full UI with bots, memory, knowledge, and gateway:
🦞 **PraisonAI Claw** — full UI with bots, memory, knowledge, and gateway:
```bash
pip install "praisonai[claw]"
praisonai claw
```
🔗 **PraisonAI Flow** — Langflow Visual Flow Builder:
```bash
pip install "praisonai[flow]"
praisonai flow
```
🤖 **PraisonAI UI** — Clean chat interface:
```bash
pip install "praisonai[ui]"
praisonai ui
```
### JavaScript SDK
```bash
@@ -314,7 +367,7 @@ agent.chat("Hello!") # Auto-persists messages, runs, traces
> 📖 [Full persistence docs](https://docs.praison.ai/docs/databases/overview) — PostgreSQL, MySQL, SQLite, MongoDB, Redis, and 20+ more
### 6. AgentClaw 🦞 (Dashboard UI)
### 6. PraisonAI Claw 🦞 (Dashboard UI)
Connect your AI agents to **Telegram, Discord, Slack, WhatsApp** and more — all from a single command.
@@ -327,6 +380,28 @@ Open **http://localhost:8082** — the dashboard comes with 13 built-in pages: C
> 📖 [Full Claw docs](https://docs.praison.ai/docs/concepts/claw) — platform tokens, CLI options, Docker, and YAML agent mode
### 7. Langflow Integration 🔗 (Visual Flow Builder)
Build multi-agent workflows visually with **drag-and-drop** components in Langflow.
```bash
pip install "praisonai[flow]"
praisonai flow
```
Open **http://localhost:7861** — use the **Agent** and **Agent Team** components to create sequential or parallel workflows. Connect Chat Input → Agent Team → Chat Output for instant multi-agent pipelines.
> 📖 [Full Flow docs](https://docs.praison.ai/docs/concepts/flow) — visual agent building, component reference, and deployment
### 8. PraisonAI UI 🤖 (Clean Chat)
Lightweight chat interface for your AI agents.
```bash
pip install "praisonai[ui]"
praisonai ui
```
---
## 📄 Using YAML (No Code)
+26 -55
View File
@@ -28,40 +28,23 @@ from praisonaiagents import Agent, AutoAgents, AutoRagAgent, ContextAgent, DeepR
Methods:
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">achat</a>(prompt: str, temperature = 1.0, tools = None, output_json = None, output_pydantic = None, reasoning_steps = False, task_name = None, task_description = None, task_id = None, attachments = None)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">aexecute</a>(task, context = None)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">agent_id</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">agent_id</a>() -> str</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">analyze_prompt</a>(prompt: str) -> set</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">arun</a>(prompt: str, **kwargs)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">as_tool</a>(description: Optional[str] = None, tool_name: Optional[str] = None) -> 'Handoff'</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">astart</a>(prompt: str, **kwargs)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">auto_memory</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">auto_memory</a>(value)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">background</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">background</a>(value)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">chat</a>(prompt, temperature = 1.0, tools = None, output_json = None, output_pydantic = None, reasoning_steps = False, stream = None, task_name = None, task_description = None, task_id = None, config = None, force_retrieval = False, skip_retrieval = False, attachments = None, tool_choice = None)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">auto_memory</a>() -> Optional[bool]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">auto_memory</a>(value: Optional[bool]) -> None</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">background</a>() -> Optional[bool]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">background</a>(value: Optional[bool]) -> None</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">chat_with_context</a>(message: str, context: 'ContextPack', **kwargs) -> str</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">check_pending_approvals</a>() -> Dict[str, Any]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">checkpoints</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">checkpoints</a>(value)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">clean_json_output</a>(output: str) -> str</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">clear_history</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">console</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">context_manager</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">checkpoints</a>() -> Optional[bool]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">checkpoints</a>(value: Optional[bool]) -> None</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">console</a>() -> Optional[Any]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">context_manager</a>() -> Optional[Any]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">context_manager</a>(value)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">cost_summary</a>() -> dict</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">delete_history</a>(index: int) -> bool</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">delete_history_matching</a>(pattern: str) -> int</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">diff</a>(from_hash: Optional[str] = None)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">display_name</a>() -> str</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">ephemeral</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">execute</a>(task, context = None)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">execute_tool</a>(function_name, arguments, tool_call_id = None)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">execute_tool_async</a>(function_name: str, arguments: Dict[str, Any]) -> Any</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">from_template</a>(uri: str, config: Optional[Dict[str, Any]] = None, offline: bool = False, **kwargs) -> 'Agent'</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">generate_task</a>() -> 'Task'</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">get_available_tools</a>() -> List[Any]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">get_history_size</a>() -> int</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">get_learn_context</a>() -> str</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">get_memory_context</a>(query: Optional[str] = None) -> str</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">get_recommended_stage</a>(prompt: str) -> str</code>
@@ -69,37 +52,28 @@ Methods:
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">get_skills_prompt</a>() -> str</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">handoff_to</a>(target_agent: 'Agent', prompt: str, context: Optional[Dict[str, Any]] = None, config: Optional['HandoffConfig'] = None) -> 'HandoffResult'</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">handoff_to_async</a>(target_agent: 'Agent', prompt: str, context: Optional[Dict[str, Any]] = None, config: Optional['HandoffConfig'] = None) -> 'HandoffResult'</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">iter_stream</a>(prompt: str, **kwargs)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">launch</a>(path: str = '/', port: int = 8000, host: str = '0.0.0.0', debug: bool = False, protocol: str = 'http')</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">llm_model</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">output_style</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">output_style</a>(value)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">pending_approval_count</a>() -> int</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">policy</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">policy</a>(value)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">prune_history</a>(keep_last: int = 5) -> int</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">llm_model</a>() -> Optional[str]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">output_style</a>() -> Optional[str]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">output_style</a>(value: Optional[str]) -> None</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">policy</a>() -> Optional[Any]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">policy</a>(value: Optional[Any]) -> None</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">query</a>(question: str, **kwargs) -> 'RAGResult'</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">rag</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">rag</a>() -> Optional[Any]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">rag_query</a>(question: str, **kwargs) -> 'RAGResult'</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">redo</a>() -> bool</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">retrieval_config</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">retrieval_config</a>() -> Optional[Any]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">retrieve</a>(query: str, **kwargs) -> 'ContextPack'</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">rules_manager</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">run</a>(prompt: str, **kwargs)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">rules_manager</a>() -> Optional[Any]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">run_autonomous</a>(prompt: str, max_iterations: Optional[int] = None, timeout_seconds: Optional[float] = None, completion_promise: Optional[str] = None, clear_context: bool = False)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">run_autonomous_async</a>(prompt: str, max_iterations: Optional[int] = None, timeout_seconds: Optional[float] = None, completion_promise: Optional[str] = None, clear_context: bool = False)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">run_until</a>(prompt: str, criteria: str, threshold: float = 8.0, max_iterations: int = 5, mode: str = 'optimize', on_iteration: Optional[Callable[[Any], None]] = None, verbose: bool = False) -> 'EvaluationLoopResult'</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">run_until_async</a>(prompt: str, criteria: str, threshold: float = 8.0, max_iterations: int = 5, mode: str = 'optimize', on_iteration: Optional[Callable[[Any], None]] = None, verbose: bool = False) -> 'EvaluationLoopResult'</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">session_id</a>() -> Optional[str]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">skill_manager</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">start</a>(prompt: str = None, **kwargs)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">store_memory</a>(content: str, memory_type: str = 'short_term', **kwargs)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">stream_emitter</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">stream_emitter</a>(value)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">submit_for_approval</a>(function_name: str, arguments: Dict[str, Any]) -> str</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">switch_model</a>(new_model: str) -> None</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">thinking_budget</a>()</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">thinking_budget</a>(value)</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">skill_manager</a>() -> Optional[Any]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">store_memory</a>(content: str, memory_type: str = 'short_term', **kwargs: Any) -> None</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">stream_emitter</a>() -> Optional[Any]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">stream_emitter</a>(value: Optional[Any]) -> None</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">thinking_budget</a>() -> Optional[int]</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">thinking_budget</a>(value: Optional[int]) -> None</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">total_cost</a>() -> float</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">undo</a>() -> bool</code>
* <code title="class AutoAgents">AutoAgents.<a href="./src/praisonai-agents/praisonaiagents/agents/autoagents.py">astart</a>()</code>
@@ -874,6 +848,8 @@ Methods:
* <code title="cli">praisonai examples run <a href="./src/praisonai/praisonai/cli/commands/examples.py">--help</a></code>
* <code title="cli">praisonai examples run-all <a href="./src/praisonai/praisonai/cli/commands/examples.py">--help</a></code>
* <code title="cli">praisonai examples stats <a href="./src/praisonai/praisonai/cli/commands/examples.py">--help</a></code>
* <code title="cli">praisonai flow flow-start <a href="./src/praisonai/praisonai/cli/commands/flow.py">--help</a></code>
* <code title="cli">praisonai flow version <a href="./src/praisonai/praisonai/cli/commands/flow.py">--help</a></code>
* <code title="cli">praisonai gateway channels <a href="./src/praisonai/praisonai/cli/commands/gateway.py">--help</a></code>
* <code title="cli">praisonai gateway gateway-callback <a href="./src/praisonai/praisonai/cli/commands/gateway.py">--help</a></code>
* <code title="cli">praisonai gateway send <a href="./src/praisonai/praisonai/cli/commands/gateway.py">--help</a></code>
@@ -1045,12 +1021,7 @@ Methods:
* <code title="cli">praisonai train llm <a href="./src/praisonai/praisonai/cli/commands/train.py">--help</a></code>
* <code title="cli">praisonai train show <a href="./src/praisonai/praisonai/cli/commands/train.py">--help</a></code>
* <code title="cli">praisonai train train-callback <a href="./src/praisonai/praisonai/cli/commands/train.py">--help</a></code>
* <code title="cli">praisonai ui bot <a href="./src/praisonai/praisonai/cli/commands/ui.py">--help</a></code>
* <code title="cli">praisonai ui chat <a href="./src/praisonai/praisonai/cli/commands/ui.py">--help</a></code>
* <code title="cli">praisonai ui code <a href="./src/praisonai/praisonai/cli/commands/ui.py">--help</a></code>
* <code title="cli">praisonai ui gradio <a href="./src/praisonai/praisonai/cli/commands/ui.py">--help</a></code>
* <code title="cli">praisonai ui realtime <a href="./src/praisonai/praisonai/cli/commands/ui.py">--help</a></code>
* <code title="cli">praisonai ui ui-main <a href="./src/praisonai/praisonai/cli/commands/ui.py">--help</a></code>
* <code title="cli">praisonai ui ui <a href="./src/praisonai/praisonai/cli/commands/ui.py">--help</a></code>
* <code title="cli">praisonai version check <a href="./src/praisonai/praisonai/cli/commands/version.py">--help</a></code>
* <code title="cli">praisonai version show <a href="./src/praisonai/praisonai/cli/commands/version.py">--help</a></code>
* <code title="cli">praisonai version version-callback <a href="./src/praisonai/praisonai/cli/commands/version.py">--help</a></code>
+1 -1
View File
@@ -16,7 +16,7 @@ RUN mkdir -p /root/.praison
# Install Python packages (using latest versions)
RUN pip install --no-cache-dir \
praisonai_tools \
"praisonai>=4.5.88" \
"praisonai>=4.5.112" \
"praisonai[chat]" \
"embedchain[github,youtube]"
+1 -1
View File
@@ -20,7 +20,7 @@ RUN mkdir -p /root/.praison
# Install Python packages (using latest versions)
RUN pip install --no-cache-dir \
praisonai_tools \
"praisonai>=4.5.88" \
"praisonai>=4.5.112" \
"praisonai[ui]" \
"praisonai[chat]" \
"praisonai[realtime]" \
+1 -1
View File
@@ -16,7 +16,7 @@ RUN mkdir -p /root/.praison
# Install Python packages (using latest versions)
RUN pip install --no-cache-dir \
praisonai_tools \
"praisonai>=4.5.88" \
"praisonai>=4.5.112" \
"praisonai[ui]" \
"praisonai[crewai]"
+2 -2
View File
@@ -37,7 +37,7 @@ def example_simple_enable():
instructions="You are a helpful assistant",
memory=True, # Enable memory with defaults
reflection=True, # Enable self-reflection
web=True, # Enable web search + fetch
web=WebConfig(fetch=False), # Enable web search + fetch
)
print(f"Agent created with memory={agent._memory_instance is not None}")
print(f" self_reflect={agent.self_reflect}")
@@ -152,7 +152,7 @@ def example_string_presets():
instructions="You are a verbose assistant",
output="verbose", # String preset for output
execution="fast", # String preset for execution
web="tavily", # String preset for web provider
web=["tavily", {"fetch": False}], # String preset with override for web provider
)
print(f"Output preset 'verbose': verbose={agent.verbose}, metrics={agent.metrics}")
print(f"Execution preset 'fast': max_iter={agent.max_iter}")
+3 -3
View File
@@ -5,14 +5,14 @@ both files to verify everything looks good.
"""
from praisonaiagents import Agent
from praisonaiagents.tools import (
write_file, read_file, execute_command, list_directory
write_file, read_file, execute_command, list_files
)
agent = Agent(
instructions="You are a helpful coding assistant.",
output="editor",
tools=[write_file, read_file, execute_command, list_directory],
approval=True,
tools=[write_file, read_file, execute_command, list_files],
approval=False,
)
agent.start(
"Create a Python file at /tmp/fibonacci.py that generates the first 20 "
+4 -4
View File
@@ -5,22 +5,22 @@ markdown report, reads it back, lists files, and gets system info.
"""
from praisonaiagents import Agent
from praisonaiagents.tools import (
write_file, read_file, execute_command, list_directory, get_system_info
write_file, read_file, execute_command, list_files, get_system_info
)
try:
from praisonaiagents.tools import web_search
tools = [web_search, write_file, read_file, execute_command,
list_directory, get_system_info]
list_files, get_system_info]
except ImportError:
tools = [write_file, read_file, execute_command,
list_directory, get_system_info]
list_files, get_system_info]
agent = Agent(
instructions="You are a helpful research assistant.",
output="editor",
tools=tools,
approval=True,
approval=False,
)
agent.start(
"Research the top 3 Python web frameworks (Django, FastAPI, Flask), then: "
+4 -4
View File
@@ -5,20 +5,20 @@ it, and lists created files.
"""
from praisonaiagents import Agent
from praisonaiagents.tools import (
write_file, execute_command, list_directory
write_file, execute_command, list_files
)
try:
from praisonaiagents.tools import web_search
tools = [web_search, write_file, execute_command, list_directory]
tools = [web_search, write_file, execute_command, list_files]
except ImportError:
tools = [write_file, execute_command, list_directory]
tools = [write_file, execute_command, list_files]
agent = Agent(
instructions="You are a helpful research assistant.",
output="editor",
tools=tools,
approval=True,
approval=False,
)
agent.start(
"Search the web for the current weather in Tokyo, create a JSON file at "
+2 -2
View File
@@ -4,8 +4,8 @@ from praisonai.persistence import create_conversation_store
store = create_conversation_store("sqlite", path="/tmp/multi_agent.db")
agent1 = Agent(name="Researcher", llm="gpt-4o-mini", db=store, session_id="shared-session")
agent2 = Agent(name="Writer", llm="gpt-4o-mini", db=store, session_id="shared-session")
agent1 = Agent(name="Researcher", llm="gpt-4o-mini", memory={"backend": "sqlite", "session_id": "shared-session", "db": store})
agent2 = Agent(name="Writer", llm="gpt-4o-mini", memory={"backend": "sqlite", "session_id": "shared-session", "db": store})
r1 = agent1.chat("Research topic: AI in healthcare. Key finding: reduces diagnosis time by 50%")
print(f"Researcher: {r1[:50]}...")
+117
View File
@@ -0,0 +1,117 @@
"""
SandlockSandbox Security Demo
Demonstrates how to use SandlockSandbox for kernel-level code isolation.
Requires: pip install 'praisonai[sandbox]' (installs sandlock)
"""
import asyncio
from praisonaiagents.sandbox import ResourceLimits, SecurityPolicy, SandboxConfig
async def demonstrate_sandlock_security():
"""Show SandlockSandbox blocking malicious operations."""
try:
from praisonai.sandbox import SandlockSandbox
except ImportError:
print("❌ SandlockSandbox requires: pip install 'praisonai[sandbox]'")
print(" Falling back to SubprocessSandbox (less secure)")
from praisonai.sandbox import SubprocessSandbox
sandbox = SubprocessSandbox()
else:
# Create sandbox with strict security policy
config = SandboxConfig.native(
writable_paths=["./safe_workspace"], # Only allow writes to this dir
network=False, # Block all network access
)
sandbox = SandlockSandbox(config)
print("✅ Using SandlockSandbox with kernel-level isolation")
await sandbox.start()
# Test 1: Safe code execution
print("\n🟢 Test 1: Safe Python code")
result = await sandbox.execute(
"print('Hello from isolated sandbox!')",
limits=ResourceLimits.minimal()
)
print(f"Status: {result.status}")
print(f"Output: {result.stdout}")
# Test 2: Attempt file system access (should be blocked by Landlock)
print("\n🔒 Test 2: Attempt to read sensitive files")
result = await sandbox.execute("""
try:
with open('/etc/passwd', 'r') as f:
print(f.read()[:100])
except Exception as e:
print(f'Access blocked: {e}')
""")
print(f"Status: {result.status}")
print(f"Output: {result.stdout}")
if result.stderr:
print(f"Stderr: {result.stderr}")
# Test 3: Attempt network access (should be blocked)
print("\n🌐 Test 3: Attempt network access")
result = await sandbox.execute("""
try:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('example.com', 80))
print('Network connection successful')
s.close()
except Exception as e:
print(f'Network blocked: {e}')
""")
print(f"Status: {result.status}")
print(f"Output: {result.stdout}")
# Test 4: Attempt subprocess execution (blocked by seccomp)
print("\n🚫 Test 4: Attempt subprocess execution")
result = await sandbox.execute("""
try:
import subprocess
result = subprocess.run(['ls', '/'], capture_output=True, text=True)
print(f'Command output: {result.stdout}')
except Exception as e:
print(f'Subprocess blocked: {e}')
""")
print(f"Status: {result.status}")
print(f"Output: {result.stdout}")
# Test 5: Resource limits in action
print("\n⏱️ Test 5: Resource limits (timeout)")
result = await sandbox.execute(
"import time; time.sleep(100)", # Will timeout
limits=ResourceLimits(timeout_seconds=2)
)
print(f"Status: {result.status}")
print(f"Error: {result.error}")
await sandbox.stop()
# Show security features
status = sandbox.get_status()
if 'features' in status:
print(f"\n🛡️ Security features enabled:")
for feature, enabled in status['features'].items():
emoji = "✅" if enabled else "❌"
print(f" {emoji} {feature}: {enabled}")
if __name__ == "__main__":
print("🔒 SandlockSandbox Security Demonstration")
print("="*50)
asyncio.run(demonstrate_sandlock_security())
print("\n" + "="*50)
print("🎯 Key Security Benefits:")
print(" • Landlock: Kernel-enforced filesystem allowlisting")
print(" • seccomp-bpf: System call filtering")
print(" • Resource limits: Memory, CPU, process constraints")
print(" • Network isolation: Block unauthorized connections")
print(" • ~5ms overhead: Faster than Docker containers")
print(" • No root required: User-space security")
+1 -5
View File
@@ -5,11 +5,7 @@ from praisonaiagents import Agent
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant with access to documents.",
knowledge=["./docs/guide.pdf"], # Add your documents here
knowledge={
"vector_store": "chroma",
"path": "/tmp/chroma_demo"
}
knowledge={"sources": ["./docs/guide.pdf"], "vector_store": {"provider": "chroma", "path": "/tmp/chroma_demo"}}
)
# Chat - agent uses knowledge for RAG
+1 -5
View File
@@ -5,11 +5,7 @@ from praisonaiagents import Agent
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant with access to documents.",
knowledge=["./docs/guide.pdf"], # Add your documents here
knowledge={
"vector_store": "lancedb",
"path": "/tmp/lancedb_test"
}
knowledge={"sources": ["./docs/guide.pdf"], "vector_store": {"provider": "lancedb", "path": "/tmp/lancedb_test"}}
)
# Chat - agent uses knowledge for RAG
+1 -5
View File
@@ -5,11 +5,7 @@ from praisonaiagents import Agent
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant with access to documents.",
knowledge=["./docs/guide.pdf"], # Add your documents here
knowledge={
"vector_store": "lancedb",
"path": "/tmp/lancedb_demo"
}
knowledge={"sources": ["./docs/guide.pdf"], "vector_store": {"provider": "lancedb", "path": "/tmp/lancedb_demo"}}
)
# Chat - agent uses knowledge for RAG
+1 -5
View File
@@ -11,11 +11,7 @@ url = os.getenv("PGVECTOR_URL", "postgresql://postgres:postgres@localhost:5433/p
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant with access to documents.",
knowledge=["./docs/guide.pdf"], # Add your documents here
knowledge={
"vector_store": "pgvector",
"url": url
}
knowledge={"sources": ["./docs/guide.pdf"], "vector_store": {"provider": "pgvector", "url": url}}
)
# Chat - agent uses knowledge for RAG
+1 -5
View File
@@ -11,11 +11,7 @@ url = os.getenv("PGVECTOR_URL", "postgresql://postgres:postgres@localhost:5433/p
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant with access to documents.",
knowledge=["./docs/guide.pdf"], # Add your documents here
knowledge={
"vector_store": "pgvector",
"url": url
}
knowledge={"sources": ["./docs/guide.pdf"], "vector_store": {"provider": "pgvector", "url": url}}
)
# Chat - agent uses knowledge for RAG
+1 -1
View File
@@ -15,8 +15,8 @@ if not api_key:
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant with access to documents.",
knowledge=["./docs/guide.pdf"], # Add your documents here
knowledge={
"sources": ["./docs/guide.pdf"],
"vector_store": "pinecone",
"api_key": api_key,
"environment": "us-east-1"
+1 -5
View File
@@ -11,11 +11,7 @@ url = os.getenv("QDRANT_URL", "http://localhost:6333")
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant with access to documents.",
knowledge=["./docs/guide.pdf"], # Add your documents here
knowledge={
"vector_store": "qdrant",
"url": url
}
knowledge={"sources": ["./docs/guide.pdf"], "vector_store": {"provider": "qdrant", "url": url}}
)
# Chat - agent uses knowledge for RAG
+1 -1
View File
@@ -16,8 +16,8 @@ if not weaviate_key:
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant with access to documents.",
knowledge=["./docs/guide.pdf"], # Add your documents here
knowledge={
"sources": ["./docs/guide.pdf"],
"vector_store": "weaviate",
"url": weaviate_url,
"api_key": weaviate_key
+6 -6
View File
@@ -34,14 +34,14 @@ variables:
agents: # Canonical: use 'agents' instead of 'roles'
classifier:
role: Request Classifier
instructions: # Canonical |
instructions: | # Canonical
You are an expert at classifying requests into categories.
Respond with ONLY one word: 'technical', 'creative', or 'research'.
goal: Classify incoming requests accurately
researcher:
role: Research Analyst
instructions: # Canonical |
instructions: | # Canonical
You are a skilled research analyst with expertise in technology trends.
You provide concise, factual research findings with citations.
goal: Research topics thoroughly and provide insights
@@ -52,28 +52,28 @@ agents: # Canonical: use 'agents' instead of 'roles'
tech_expert:
role: Technical Expert
instructions: # Canonical |
instructions: | # Canonical
You are a technical expert with deep knowledge in AI and ML.
You provide detailed technical explanations.
goal: Handle technical questions with expertise
creative_writer:
role: Creative Writer
instructions: # Canonical |
instructions: | # Canonical
You are a creative writer who can make complex topics engaging.
You write in a clear, accessible style.
goal: Create engaging content from research
market_analyst:
role: Market Analyst
instructions: # Canonical |
instructions: | # Canonical
You analyze market trends and competitive landscapes.
You provide actionable business insights.
goal: Analyze market trends and opportunities
aggregator:
role: Synthesizer
instructions: # Canonical |
instructions: | # Canonical
You combine findings from multiple sources into coherent reports.
You identify patterns and key insights.
goal: Synthesize all findings into comprehensive reports
@@ -0,0 +1,275 @@
---
description: Review, validate, and merge GitHub pull requests or triage issues
---
# PR / Issue Review Workflow
When given a GitHub PR or Issue URL, follow this procedure end-to-end.
---
## Step 0 — Determine Type
Parse the URL to identify whether it is a **Pull Request** or an **Issue**.
```
https://github.com/MervinPraison/PraisonAI/pull/<NUMBER> → PR
https://github.com/MervinPraison/PraisonAI/issues/<NUMBER> → Issue
```
- **PR** → go to Step 1
- **Issue** → go to Step 8
---
## Step 1 — Fetch PR Metadata
// turbo
```bash
cd /Users/praison/praisonai-package && \
gh pr view <NUMBER> --json title,body,author,state,additions,deletions,changedFiles,headRefName,baseRefName,labels
```
Record: title, author, branch, file count, +/- lines.
---
## Step 2 — Read the Full Diff
// turbo
```bash
cd /Users/praison/praisonai-package && gh pr diff <NUMBER>
```
If the diff is very large (>500 lines), pipe through `head -500` first, then read remaining chunks.
---
## Step 3 — Review the Diff
For each changed file, evaluate against **PraisonAI engineering principles** (from AGENTS.md):
| Principle | What to Check |
|-----------|---------------|
| **Protocol-driven core** | No heavy implementations in `praisonaiagents/` (core SDK) |
| **Lazy imports** | Optional deps imported inside functions, not at module level |
| **DRY** | No code duplication; reuse existing abstractions |
| **Naming conventions** | `add_X()`, `get_X()`, `XConfig`, `XProtocol`, `XAdapter` |
| **Async-safe** | No blocking I/O in async context; asyncio primitives used |
| **Multi-agent safe** | No shared mutable global state without locks |
| **Thread safety** | Double-checked locking for lazy caches; `threading.Lock` for mutables |
| **Security** | No hardcoded secrets; `hmac.compare_digest` for comparisons; restricted `exec()` |
| **Backward compat** | Public API changes require deprecation cycle |
| **Test coverage** | Tests included; TDD pattern; both unit + agentic tests |
**Red flags to catch:**
- Module-level imports of optional deps (chromadb, litellm, etc.)
- Hardcoded credentials or `debug=True` in production paths
- Direct string comparison for secrets (timing attacks)
- `exec()`/`eval()` without sandbox
- Shared mutable globals without `threading.Lock`
- Missing error handling or swallowed exceptions
---
## Step 4 — Checkout and Run Tests Locally
// turbo
```bash
cd /Users/praison/praisonai-package && git checkout main && git pull origin main
```
// turbo
```bash
cd /Users/praison/praisonai-package && gh pr checkout <NUMBER>
```
Run targeted tests for changed files first:
```bash
cd /Users/praison/praisonai-package/src/praisonai-agents && \
python -m pytest tests/ -x -q \
--ignore=tests/integration/test_whatsapp_web_real.py \
--ignore=tests/unit/tools/test_profiles.py \
--tb=short 2>&1 | tail -20
```
For PRs touching security-sensitive code, also run:
```bash
# Sandbox tests
python -m pytest tests/unit/tools/test_python_tools_sandbox.py -v
# CWE-78 env injection tests
python -m pytest src/praisonai/tests/unit/test_cwe78_env_injection.py -v
# Thread-safety tests
python -m pytest tests/unit/test_thread_safety.py -v
```
---
## Step 5 — Verify No Regressions
Run the full test suite:
```bash
cd /Users/praison/praisonai-package/src/praisonai-agents && \
python -m pytest tests/ -q \
--ignore=tests/integration/test_whatsapp_web_real.py \
--ignore=tests/unit/tools/test_profiles.py \
--tb=no 2>&1 | tail -5
```
**Acceptable result:** All tests pass, or only pre-existing flaky tests fail (e.g., `test_file_memory.py::test_memory_persistence_across_agent_instances`).
**Unacceptable:** Any NEW failure introduced by the PR.
---
## Step 6 — Approve or Request Changes
**If the PR is good:**
```bash
cd /Users/praison/praisonai-package && \
gh pr review <NUMBER> --approve --body "LGTM — reviewed diff, tests pass, follows PraisonAI engineering principles."
```
**If changes are needed:**
```bash
cd /Users/praison/praisonai-package && \
gh pr review <NUMBER> --request-changes --body "Requesting changes: <specific feedback>"
```
---
## Step 7 — Merge
```bash
cd /Users/praison/praisonai-package && \
gh pr merge <NUMBER> --merge --subject "<PR title>"
```
Verify merge:
// turbo
```bash
cd /Users/praison/praisonai-package && gh pr view <NUMBER> --json state,mergedAt
```
Then return to main:
// turbo
```bash
cd /Users/praison/praisonai-package && git checkout main && git pull origin main
```
---
## Step 8 — Issue Triage (if URL is an Issue)
### 8a. Fetch issue details
// turbo
```bash
cd /Users/praison/praisonai-package && \
gh issue view <NUMBER> --json title,body,author,state,labels,comments
```
### 8b. Classify severity
| Tier | Criteria | Examples |
|------|----------|---------|
| **Tier 1 — Critical** | Security vuln, data loss, crash in hot path | exec() without sandbox, hardcoded secrets, unprotected globals |
| **Tier 2 — High** | Performance regression, broken feature, wrong output | Duplicate API calls, memory leak, silent failure |
| **Tier 3 — Medium** | DX issue, missing validation, doc gap | Bad error messages, missing CLI parity, stale docs |
| **Tier 4 — Low** | Cosmetic, code style, minor refactor | Trailing whitespace, naming inconsistency |
### 8c. Deep analysis (for Tier 1-2)
1. Read ALL relevant source files end-to-end
2. Trace the code path that the issue describes
3. Identify root cause with file paths and line numbers
4. Assess blast radius (what else could be affected)
5. Determine if the issue is **actually what it claims** (re-classify if needed)
### 8d. Delegate Implementation to GitHub Workflow Agents
> **KEY PHILOSOPHY: We act as the Manager, GitHub Actions execute the Workflow.**
**DO NOT implement the fix yourself locally.** PraisonAI uses autonomous GitHub Action workflows (such as `gemini-issue-review.yml` and `claude.yml`) to automatically resolve issues and create PRs. Your job as the local agent is to supervise, analyze gaps, and trigger these cloud agents to do the heavy lifting. If there is a gap (e.g. strict test violations), provide detailed relevant information in the PR/Issue and trigger the agents again.
1. Issue the command to trigger the cloud agent on the issue:
```bash
cd /Users/praison/praisonai-package && \
gh issue comment <NUMBER> --body "@gemini please review and fix this issue"
```
*(Note: You can use `@claude` or `@gemini` depending on preference or active bots).*
2. Check the GitHub Actions logs (`gh run list`) and wait for the cloud agent to open a Pull Request (`gh pr list`).
3. Once the cloud bot opens a Pull Request for the issue, return to **Step 1** to review the PR, test the branch locally, and merge it if it passes the checks.
---
## Step 9 — (Skipped) Local PR Creation
> **Note:** As the local agent, you should delegate code fixes to the cloud agents. Only implement code locally and create a PR if the USER explicitly forces you to bypass the cloud agents. If forced, use standard prefixes: `fix:`, `feat:`, `security:`, `refactor:`, `docs:`, `test:`.
---
## Step 10 — Security-Specific Checks
When reviewing security-related PRs, additionally verify:
### Credentials / Secrets
```bash
# Check for hardcoded secrets
grep -rn "secret\|password\|token\|api_key" --include="*.py" <changed-files> | \
grep -v "test_\|#\|environ\|getenv\|config"
```
### Timing Attacks
```bash
# Ensure hmac.compare_digest for secret comparisons
grep -rn "==.*api_key\|==.*secret\|==.*token" --include="*.py" <changed-files>
```
### Authentication & Workflow Secrets
When reviewing GitHub Actions workflows (especially ones using cloud actions like `claude-code-action`):
- **OIDC Validation**: Any workflow using OIDC to authenticate with a cloud provider (e.g. AWS Bedrock for Claude, GCP for Vertex) **MUST** include `id-token: write` in the job's `permissions`. Without it, you will see `Could not fetch an OIDC token` errors.
- **Valid PAT Usage**: When injecting tokens into workflows via `github_token:`, ensure you use `secrets.GH_TOKEN`. `secrets.PAT_TOKEN` has been known to be invalid or cause `401 Bad credentials` errors when curling GitHub resources. By design, `@copilot` mentions also strictly require `GH_TOKEN`.
### Supply Chain
```bash
# Check dependency versions
pip show <package-name>
# Check for known compromised versions
pip install <package>==999 2>&1 | grep "from versions"
```
### IoC Scanning
```bash
# Check for known malicious files
find $(python -c "import site; print(site.getsitepackages()[0])") -name "<suspicious-file>" 2>/dev/null
```
---
## Quick Reference — Common Commands
| Action | Command |
|--------|---------|
| View PR | `gh pr view <N> --json title,body,state,additions,deletions` |
| View diff | `gh pr diff <N>` |
| Checkout PR | `gh pr checkout <N>` |
| List open PRs | `gh pr list` |
| List open issues | `gh issue list` |
| View issue | `gh issue view <N>` |
| Approve PR | `gh pr review <N> --approve` |
| Request changes | `gh pr review <N> --request-changes --body "..."` |
| Merge PR | `gh pr merge <N> --merge` |
| Create PR | `gh pr create --title "..." --body "..." --head <branch> --base main` |
| Run tests | `cd src/praisonai-agents && python -m pytest tests/ -q --tb=no` |
| Check dep version | `pip show <package>` |
@@ -4,16 +4,18 @@ description: PR review chain — how automated reviews flow for every PR
## Review Chain (Sequential)
> **KEY PHILOSOPHY: We act as the Manager, GitHub Actions execute the Workflow.**
> As the local agent, our job is to analyze, supervise, and coordinate the cloud bots. If we identify a gap in the review chain or code (e.g., missing tests), provide detailed relevant information and trigger the agents (like `@claude`) again.
```
PR opened
↓
CodeRabbit (@coderabbitai) ─── auto for human PRs, triggered via comment for bot PRs
Qodo (/review) ─── auto for human PRs, triggered via comment for bot PRs
Gemini (@gemini) ─── triggered via comment for bot PRs
↓ (~3-5 min)
Gemini (@gemini) ─── triggered via comment for bot PRs/Issues
↓ (~3-5 min) ↓ (auto triggers Claude on completion)
Copilot (@copilot) ─── triggered ONLY after CodeRabbit or Qodo post their review
↓
Claude (@claude) ─── triggered ONLY after Copilot submits review (final reviewer)
Claude (@claude) ─── triggered ONLY after Copilot OR Gemini finishes (final reviewer)
```
## Workflow Files
@@ -21,7 +23,7 @@ Claude (@claude) ─── triggered ONLY after Copilot submits review
| File | Trigger | Does what |
|------|---------|-----------|
| `auto-pr-comment.yml` | `issue_comment`, `pull_request_review`, `pull_request:opened` | Triggers Copilot after CodeRabbit/Qodo finish. For bot PRs: triggers CodeRabbit+Qodo+Gemini first. |
| `chain-claude-after-copilot.yml` | `pull_request_review:submitted` | Triggers Claude after Copilot reviews. |
| `chain-claude-after-copilot.yml` | `pull_request_review:submitted`, `issue_comment` | Triggers Claude after Copilot reviews, AND automatically after Gemini Code Assist finishes fixing issues/PRs. |
| `claude.yml` | `issue_comment`, `pull_request_review_comment`, `issues:assigned/labeled` | Claude responds to @claude mentions. |
## Bot PR fix
@@ -35,3 +37,8 @@ CodeRabbit and Qodo skip `github-actions[bot]` authored PRs by default. The `bot
- Claude NEVER triggers before Copilot completes.
- Duplicate `@copilot` comments are prevented by checking existing comments.
- PraisonAI PRs: NEVER merge automatically — user merges manually.
## Security & Credentials
- **OIDC Configuration (`id-token: write`)**: Any workflow utilizing the `anthropics/claude-code-action@beta` (or similar actions requiring JWTs for AWS Bedrock/GCP Vertex) MUST define `id-token: write` under the job's `permissions` block. Missing this causes deep, opaque failures like "Could not fetch an OIDC token" paired with `Bad credentials` execution limits.
- **Valid `github_token` Payload**: Always pass `secrets.GH_TOKEN` into `github_token` inputs rather than `secrets.PAT_TOKEN`, as the latter has historically proven invalid and caused silent 401 exceptions on curl requests behind the scenes.
+3 -1
View File
@@ -93,4 +93,6 @@ chroma_db/
.praisonai
.windsurf
.agent
.ruff_cache
*.sfdx
.sfdx/
+20
View File
@@ -0,0 +1,20 @@
import cProfile
import pstats
import io
from praisonaiagents import Agent
# Warm up
for _ in range(100):
_ = Agent(name="Test", llm="gpt-4o-mini", output="silent")
pr = cProfile.Profile()
pr.enable()
for _ in range(5000):
_ = Agent(name="Test", llm="gpt-4o-mini", output="silent")
pr.disable()
s = io.StringIO()
ps = pstats.Stats(pr, stream=s).sort_stats('cumtime')
ps.print_stats(30)
print(s.getvalue())
@@ -0,0 +1,31 @@
import cProfile
import pstats
import io
import time
from praisonaiagents import Agent
def func():
return Agent(name='Test', llm='gpt-4o-mini', output="silent")
# Warm up to fill caches
for _ in range(100):
func()
start_time = time.perf_counter()
for _ in range(1000):
func()
end_time = time.perf_counter()
avg_time = (end_time - start_time) / 1000 * 1_000_000
print(f"Time without profile: {avg_time:.2f} μs")
pr = cProfile.Profile()
pr.enable()
for _ in range(1000):
func()
pr.disable()
s = io.StringIO()
ps = pstats.Stats(pr, stream=s).sort_stats('cumtime')
ps.print_stats(30)
print(s.getvalue())
@@ -499,43 +499,6 @@ _LAZY_IMPORTS = {
'StructuredFormatter': ('praisonaiagents._logging', 'StructuredFormatter'),
}
def _custom_handler(name, cache):
"""Handle special cases that need custom logic."""
import warnings
# Agents is a silent alias for AgentManager
if name == "Agents":
value = lazy_import('praisonaiagents.agents.agents', 'AgentManager', cache)
cache['AgentManager'] = value
cache['Agents'] = value
return value
# Module imports (return the module itself)
if name == 'tools':
import importlib
mod = importlib.import_module('.tools', 'praisonaiagents')
cache['tools'] = mod
return mod
if name == 'config':
import importlib
mod = importlib.import_module('.config', 'praisonaiagents')
cache['config'] = mod
return mod
if name == 'memory':
import importlib
mod = importlib.import_module('.memory', 'praisonaiagents')
cache['memory'] = mod
return mod
if name == 'workflows':
import importlib
mod = importlib.import_module('.workflows', 'praisonaiagents')
cache['workflows'] = mod
return mod
raise AttributeError(f"Not handled by custom_handler: {name}")
# ============================================================================
# SUBPACKAGE FUNCTION OVERRIDES
# ============================================================================
@@ -583,8 +546,50 @@ class _EmbeddingProxy:
def __repr__(self):
return f"<lazy proxy for {self._load()!r}>"
_global_embedding_proxy = _EmbeddingProxy()
def _custom_handler(name, cache):
"""Handle special cases that need custom logic."""
import warnings
# Agents is a silent alias for AgentManager
if name == "Agents":
value = lazy_import('praisonaiagents.agents.agents', 'AgentManager', cache)
cache['AgentManager'] = value
cache['Agents'] = value
return value
# Handle embedding specifically if missing from module dict due to submodule reload
if name in ("embedding", "embeddings"):
return _global_embedding_proxy
# Module imports (return the module itself)
if name == 'tools':
import importlib
mod = importlib.import_module('.tools', 'praisonaiagents')
cache['tools'] = mod
return mod
if name == 'config':
import importlib
mod = importlib.import_module('.config', 'praisonaiagents')
cache['config'] = mod
return mod
if name == 'memory':
import importlib
mod = importlib.import_module('.memory', 'praisonaiagents')
cache['memory'] = mod
return mod
if name == 'workflows':
import importlib
mod = importlib.import_module('.workflows', 'praisonaiagents')
cache['workflows'] = mod
return mod
raise AttributeError(f"Not handled by custom_handler: {name}")
# Override the submodule with our function proxy
embedding = _EmbeddingProxy()
embedding = _global_embedding_proxy
embeddings = embedding # embeddings is an alias
@@ -174,6 +174,18 @@ def __getattr__(name):
from .session_manager import SessionManagerMixin
_lazy_cache[name] = SessionManagerMixin
return SessionManagerMixin
elif name == 'ChatMixin':
from .chat_mixin import ChatMixin
_lazy_cache[name] = ChatMixin
return ChatMixin
elif name == 'ExecutionMixin':
from .execution_mixin import ExecutionMixin
_lazy_cache[name] = ExecutionMixin
return ExecutionMixin
elif name == 'MemoryMixin':
from .memory_mixin import MemoryMixin
_lazy_cache[name] = MemoryMixin
return MemoryMixin
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
@@ -239,4 +251,7 @@ __all__ = [
'ToolExecutionMixin',
'ChatHandlerMixin',
'SessionManagerMixin',
'ChatMixin',
'ExecutionMixin',
'MemoryMixin',
]
File diff suppressed because it is too large. Load diff
@@ -9,6 +9,7 @@ Follows the Agent() class patterns:
"""
import os
import logging
from praisonaiagents._logging import get_logger
import warnings
from dataclasses import dataclass, field
from typing import Optional, Any, Dict, Union, BinaryIO
@@ -17,7 +18,6 @@ from pathlib import Path
# Filter out Pydantic warning about fields
warnings.filterwarnings("ignore", "Valid config keys have changed in V2", UserWarning)
# ─────────────────────────────────────────────────────────────────────────────
# AudioConfig - Configuration dataclass following feature_configs.py patterns
# ─────────────────────────────────────────────────────────────────────────────
@@ -59,7 +59,6 @@ class AudioConfig:
"api_key": self.api_key,
}
# ─────────────────────────────────────────────────────────────────────────────
# AudioAgent Class - Agent-centric audio processing
# ─────────────────────────────────────────────────────────────────────────────
@@ -192,10 +191,10 @@ class AudioAgent:
def _configure_logging(self, verbose: Union[bool, int]) -> None:
"""Configure logging levels."""
if isinstance(verbose, int) and verbose >= 10:
logging.getLogger("litellm").setLevel(logging.DEBUG)
get_logger("litellm").setLevel(logging.DEBUG)
else:
logging.getLogger("litellm").setLevel(logging.WARNING)
logging.getLogger("httpx").setLevel(logging.WARNING)
get_logger("litellm").setLevel(logging.WARNING)
get_logger("httpx").setLevel(logging.WARNING)
def _get_model_params(self, model: Optional[str] = None) -> Dict[str, Any]:
"""Build parameters for LiteLLM calls."""
@@ -35,8 +35,9 @@ from dataclasses import dataclass, field
from typing import Optional, Dict, Any, List, Set
from enum import Enum
import logging
from praisonaiagents._logging import get_logger
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
# ============================================================================
# Unified Stage Enum (G-DUP-1 fix: single source of truth)
@@ -72,7 +73,6 @@ _ESCALATION_TO_AUTONOMY_SIGNAL = {
# Reverse map for converting autonomy signal strings back to EscalationSignal values
_AUTONOMY_TO_ESCALATION_SIGNAL = {v: k for k, v in _ESCALATION_TO_AUTONOMY_SIGNAL.items()}
# Valid autonomy modes
VALID_AUTONOMY_MODES = {"caller", "iterative"}
@@ -83,7 +83,6 @@ _LEVEL_TO_DEFAULT_MODE = {
"full_auto": "iterative",
}
@dataclass
class AutonomyConfig:
"""Configuration for Agent autonomy features.
@@ -196,7 +195,6 @@ class AutonomyConfig:
default_tools=data.get("default_tools"),
)
class AutonomySignal(str, Enum):
"""Signals detected from prompts for autonomy decisions.
@@ -225,7 +223,6 @@ class AutonomySignal(str, Enum):
)
super().__init_subclass__(**kwargs)
def _warn_autonomy_signal():
"""Emit deprecation warning when AutonomySignal is accessed."""
from ..utils.deprecation import warn_deprecated_param
@@ -237,7 +234,6 @@ def _warn_autonomy_signal():
stacklevel=4
)
class AutonomyTrigger:
"""Detects signals from prompts for autonomy decisions.
@@ -283,7 +279,6 @@ class AutonomyTrigger:
pass
return self._delegate.recommend_stage(esc_signals)
@dataclass
class AutonomyResult:
"""Result of an autonomous execution.
@@ -318,7 +313,6 @@ class AutonomyResult:
"""
return self.output or ""
class DoomLoopTracker:
"""Tracks actions to detect doom loops with graduated recovery.
@@ -421,7 +415,6 @@ class DoomLoopTracker:
self._delegate.start_session()
self._recovery_attempts = 0
class AutonomyMixin:
"""Helper-only trait for autonomy utilities.
@@ -1,144 +1,118 @@
"""
Chat and conversation handling functionality for Agent class.
Chat handler mixin for the Agent class.
This module contains methods related to chat, streaming, and conversation management.
Split from the main agent.py file for better maintainability.
Contains chat management, response processing, and message formatting.
Extracted from agent.py for better modularity and maintainability.
"""
import logging
import asyncio
from typing import Any, Dict, List, Optional, Union, Generator
import time
from typing import Optional, Any, Dict, List, TYPE_CHECKING
if TYPE_CHECKING:
pass
logger = logging.getLogger(__name__)
class ChatHandlerMixin:
"""Mixin class containing chat handling methods for the Agent class."""
"""Mixin providing chat handling methods for the Agent class.
def chat(self, prompt: str, temperature: float = 1.0, tools: Optional[List[Any]] = None,
output_json: Optional[str] = None, output_pydantic: Optional[Any] = None,
reasoning_steps: bool = False, stream: Optional[bool] = None,
task_name: Optional[str] = None, task_description: Optional[str] = None,
task_id: Optional[str] = None, config: Optional[Dict[str, Any]] = None,
force_retrieval: bool = False, skip_retrieval: bool = False,
attachments: Optional[List[Any]] = None, tool_choice: Optional[str] = None) -> str:
"""
Chat with the agent using a prompt.
This mixin focuses on high-level chat coordination and response processing,
while the actual LLM interaction is handled by ChatMixin.
"""
def _format_chat_response(self, response: str, metadata: Optional[Dict[str, Any]] = None) -> str:
"""Format chat response with any necessary post-processing.
Args:
prompt: The user message/prompt
temperature: Sampling temperature (0.0-2.0)
tools: Tools available for this conversation
output_json: JSON schema for structured output
output_pydantic: Pydantic model for structured output
reasoning_steps: Whether to include reasoning steps
stream: Whether to stream the response
task_name: Name of the task for context
task_description: Description of the task
task_id: Unique identifier for the task
config: Additional configuration
force_retrieval: Force knowledge retrieval
skip_retrieval: Skip knowledge retrieval
attachments: File attachments
tool_choice: Tool selection strategy
response: Raw response from the LLM
metadata: Optional metadata about the response
Returns:
The agent's response as a string
Formatted response string
"""
return self._chat_impl(
prompt=prompt,
temperature=temperature,
tools=tools,
output_json=output_json,
output_pydantic=output_pydantic,
reasoning_steps=reasoning_steps,
stream=stream,
task_name=task_name,
task_description=task_description,
task_id=task_id,
config=config,
force_retrieval=force_retrieval,
skip_retrieval=skip_retrieval,
attachments=attachments,
_trace_emitter=None,
tool_choice=tool_choice
)
if not response:
return ""
# Basic response formatting - can be extended with additional logic
formatted = response.strip()
# Add any metadata-based formatting if needed
if metadata and metadata.get('add_timestamp'):
timestamp = time.strftime('%Y-%m-%d %H:%M:%S')
formatted = f"[{timestamp}] {formatted}"
return formatted
def _chat_impl(self, prompt: str, temperature: float, tools: Optional[List[Any]],
output_json: Optional[str], output_pydantic: Optional[Any],
reasoning_steps: bool, stream: Optional[bool],
task_name: Optional[str], task_description: Optional[str],
task_id: Optional[str], config: Optional[Dict[str, Any]],
force_retrieval: bool, skip_retrieval: bool,
attachments: Optional[List[Any]], _trace_emitter: Optional[Any],
tool_choice: Optional[str] = None) -> str:
"""Internal chat implementation with full parameter control."""
raise NotImplementedError("Chat implementation moved from main Agent class")
async def achat(self, prompt: str, temperature: float = 1.0, tools: Optional[List[Any]] = None,
output_json: Optional[str] = None, output_pydantic: Optional[Any] = None,
reasoning_steps: bool = False, task_name: Optional[str] = None,
task_description: Optional[str] = None, task_id: Optional[str] = None,
attachments: Optional[List[Any]] = None) -> str:
"""Async version of chat method."""
return await self._achat_impl(
prompt=prompt,
temperature=temperature,
tools=tools,
output_json=output_json,
output_pydantic=output_pydantic,
reasoning_steps=reasoning_steps,
task_name=task_name,
task_description=task_description,
task_id=task_id,
attachments=attachments,
_trace_emitter=None
)
async def _achat_impl(self, prompt: str, temperature: float, tools: Optional[List[Any]],
output_json: Optional[str], output_pydantic: Optional[Any],
reasoning_steps: bool, task_name: Optional[str],
task_description: Optional[str], task_id: Optional[str],
attachments: Optional[List[Any]], _trace_emitter: Optional[Any]) -> str:
"""Internal async chat implementation."""
raise NotImplementedError("Async chat implementation moved from main Agent class")
def iter_stream(self, prompt: str, **kwargs) -> Generator[str, None, None]:
"""Stream chat response as an iterator."""
raise NotImplementedError("Stream iteration implementation moved from main Agent class")
def _start_stream(self, prompt: str, **kwargs) -> Generator[str, None, None]:
"""Internal streaming implementation."""
raise NotImplementedError("Stream implementation moved from main Agent class")
def clear_history(self) -> None:
"""Clear the chat history."""
if hasattr(self, 'chat_history'):
self.chat_history.clear()
logging.info(f"{self.name}: Chat history cleared")
def prune_history(self, keep_last: int = 5) -> int:
"""
Prune chat history to keep only the last N messages.
def _validate_chat_input(self, prompt: str) -> bool:
"""Validate chat input before processing.
Args:
keep_last: Number of recent messages to keep
prompt: Input prompt to validate
Returns:
Number of messages removed
True if valid, False otherwise
"""
if not hasattr(self, 'chat_history'):
return 0
if not prompt or not isinstance(prompt, str):
logger.warning("Invalid chat input: prompt must be a non-empty string")
return False
original_length = len(self.chat_history)
if original_length <= keep_last:
return 0
if len(prompt.strip()) == 0:
logger.warning("Invalid chat input: prompt cannot be empty or whitespace only")
return False
self.chat_history = self.chat_history[-keep_last:]
removed_count = original_length - len(self.chat_history)
logging.info(f"{self.name}: Pruned {removed_count} messages from history")
return removed_count
return True
def get_history_size(self) -> int:
"""Get the current chat history size."""
if hasattr(self, 'chat_history'):
return len(self.chat_history)
return 0
def _prepare_chat_context(self, prompt: str, **kwargs) -> Dict[str, Any]:
"""Prepare context for chat processing.
Args:
prompt: Input prompt
**kwargs: Additional context parameters
Returns:
Context dictionary for chat processing
"""
context = {
'prompt': prompt,
'timestamp': time.time(),
'agent_name': getattr(self, 'name', None) or 'Agent',
}
# Add any additional context from kwargs
context.update(kwargs)
return context
def _handle_chat_error(self, error: Exception, prompt: str) -> str:
"""Handle chat processing errors gracefully.
Args:
error: The exception that occurred
prompt: The original prompt that caused the error
Returns:
Error response message
"""
logger.error(f"Chat error occurred: {error}", exc_info=True)
# Return a user-friendly error message without exposing internal details.
# Include a timestamp reference so users can correlate with server logs.
error_ref = time.strftime('%Y%m%d%H%M%S')
return f"I encountered an error while processing your request (ref: {error_ref}). Please try again."
def _log_chat_interaction(self, prompt: str, response: str, duration: Optional[float] = None):
"""Log chat interaction for debugging and analytics.
Args:
prompt: Input prompt
response: Generated response
duration: Processing duration in seconds
"""
agent_name = getattr(self, 'name', None) or 'Agent'
duration_str = f" (took {duration:.2f}s)" if duration else ""
logger.debug(f"[{agent_name}] Chat interaction{duration_str}")
logger.debug(f"[{agent_name}] Prompt: {prompt[:100]}{'...' if len(prompt) > 100 else ''}")
logger.debug(f"[{agent_name}] Response: {response[:100]}{'...' if len(response) > 100 else ''}")
File diff suppressed because it is too large. Load diff
@@ -4,7 +4,7 @@ from dataclasses import dataclass, field, asdict
from typing import Any, Dict, List, Optional, Union
import asyncio
import logging
from praisonaiagents._logging import get_logger
@dataclass
class CodeConfig:
@@ -29,7 +29,6 @@ class CodeConfig:
"""Convert config to dictionary."""
return {k: v for k, v in asdict(self).items() if v is not None}
class CodeAgent:
"""Agent for code generation, execution, review, and refactoring.
@@ -96,7 +95,7 @@ class CodeAgent:
self._console = None
# Configure logging
self._logger = logging.getLogger(f"CodeAgent.{name}")
self._logger = get_logger(f"CodeAgent.{name}")
if not verbose:
self._logger.setLevel(logging.WARNING)
@@ -311,7 +310,7 @@ Follow best practices and coding standards."""
os.unlink(temp_file)
except Exception as e:
# Temp file cleanup failed - not critical
logging.getLogger(__name__).debug(f"Failed to clean up temp file {temp_file}: {e}")
get_logger(__name__).debug(f"Failed to clean up temp file {temp_file}: {e}")
async def aexecute(self, code: str, language: str = "python", **kwargs) -> Dict[str, Any]:
"""Execute code asynchronously.
@@ -14,6 +14,7 @@ This class implements proper Context Engineering principles following the PRD te
import os
import json
import logging
from praisonaiagents._logging import get_logger
from datetime import datetime
from pathlib import Path
from typing import Optional, Any, Dict, Union, List, TYPE_CHECKING
@@ -94,7 +95,6 @@ async def _async_subprocess_run(cmd: list, timeout: int = 60) -> tuple:
from ..agent.agent import Agent
from ..task import Task
class ContextAgent(Agent):
"""
Advanced Context Engineering Agent - Comprehensive context generation for AI coding assistants.
@@ -207,7 +207,7 @@ class ContextAgent(Agent):
"""Setup comprehensive logging based on debug mode."""
try:
# Create logger
self.logger = logging.getLogger(f"ContextAgent_{id(self)}")
self.logger = get_logger(f"ContextAgent_{id(self)}")
self.logger.setLevel(logging.DEBUG if self.debug_mode else logging.INFO)
# Clear existing handlers
@@ -247,7 +247,7 @@ class ContextAgent(Agent):
except Exception as e:
print(f"⚠️ Warning: Could not setup logging: {e}")
# Create a minimal logger as fallback
self.logger = logging.getLogger(f"ContextAgent_{id(self)}")
self.logger = get_logger(f"ContextAgent_{id(self)}")
self.logger.setLevel(logging.INFO)
def setup_output_directories(self):
@@ -2482,7 +2482,6 @@ This PRP provides:
lambda: self.build_implementation_blueprint(feature_request, context_analysis)
)
def create_context_agent(llm: Optional[Union[str, Any]] = None, **kwargs) -> ContextAgent:
"""
Factory function to create a ContextAgent following Context Engineering and PRD methodology.
@@ -13,16 +13,16 @@ Usage::
import json
import logging
from praisonaiagents._logging import get_logger
import os
import time
from pathlib import Path
from typing import Any, Dict, List, Optional
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
COST_DIR = Path.home() / ".praisonai" / "costs"
def save_cost_report(
agent,
session_name: Optional[str] = None,
@@ -65,7 +65,6 @@ def save_cost_report(
logger.info(f"[costs] Saved cost report to {filepath}")
return str(filepath)
def load_cost_report(session_name: str) -> Optional[Dict[str, Any]]:
"""Load a cost report by session name.
@@ -82,7 +81,6 @@ def load_cost_report(session_name: str) -> Optional[Dict[str, Any]]:
return json.load(f)
return None
def list_cost_reports(limit: int = 20) -> List[Dict[str, Any]]:
"""List recent cost reports, sorted by timestamp (newest first).
@@ -106,7 +104,6 @@ def list_cost_reports(limit: int = 20) -> List[Dict[str, Any]]:
break
return reports
def format_cost_table(reports: List[Dict[str, Any]], as_json: bool = False) -> str:
"""Format cost reports for terminal display.
@@ -35,13 +35,13 @@ Example:
import os
import logging
from praisonaiagents._logging import get_logger
import time
import asyncio
from typing import List, Optional, Any, Dict, Literal
from dataclasses import dataclass, field
from enum import Enum
# Data classes for Deep Research response types
@dataclass
class Citation:
@@ -54,7 +54,6 @@ class Citation:
def __repr__(self):
return f"Citation(title='{self.title}', url='{self.url}')"
@dataclass
class ReasoningStep:
"""Represents a reasoning step in the research process."""
@@ -64,7 +63,6 @@ class ReasoningStep:
def __repr__(self):
return f"ReasoningStep(text='{self.text[:50]}...')" if len(self.text) > 50 else f"ReasoningStep(text='{self.text}')"
@dataclass
class WebSearchCall:
"""Represents a web search call made during research."""
@@ -74,7 +72,6 @@ class WebSearchCall:
def __repr__(self):
return f"WebSearchCall(query='{self.query}', status='{self.status}')"
@dataclass
class CodeExecutionStep:
"""Represents a code execution step during research."""
@@ -84,7 +81,6 @@ class CodeExecutionStep:
def __repr__(self):
return f"CodeExecutionStep(input='{self.input_code[:50]}...')" if len(self.input_code) > 50 else f"CodeExecutionStep(input='{self.input_code}')"
@dataclass
class MCPCall:
"""Represents an MCP tool call during research."""
@@ -95,7 +91,6 @@ class MCPCall:
def __repr__(self):
return f"MCPCall(name='{self.name}', server='{self.server_label}')"
@dataclass
class FileSearchCall:
"""Represents a file search call (Gemini-specific)."""
@@ -104,7 +99,6 @@ class FileSearchCall:
def __repr__(self):
return f"FileSearchCall(stores={self.store_names})"
@dataclass
class DeepResearchResponse:
"""
@@ -149,14 +143,12 @@ class DeepResearchResponse:
sources.append({"title": c.title, "url": c.url})
return sources
class Provider(Enum):
"""Supported Deep Research providers."""
OPENAI = "openai"
GEMINI = "gemini"
LITELLM = "litellm"
class DeepResearchAgent:
"""
Agent for performing deep research using multiple provider APIs.
@@ -295,7 +287,7 @@ You are a professional research analyst. When conducting research:
self._gemini_client = None
# Configure logging
self.logger = logging.getLogger(__name__)
self.logger = get_logger(__name__)
if self.verbose:
self.logger.debug(f"DeepResearchAgent initialized: provider={self.provider.value}, model={self.model}")
@@ -12,12 +12,12 @@ Follows the Agent() class patterns with:
import os
import logging
from praisonaiagents._logging import get_logger
import math
from dataclasses import dataclass
from typing import Optional, Dict, Any, Union, List
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
@dataclass
class EmbeddingConfig:
@@ -44,7 +44,6 @@ class EmbeddingConfig:
"api_key": self.api_key,
}
class EmbeddingAgent:
"""
A specialized agent for generating text embeddings.
@@ -164,10 +163,10 @@ class EmbeddingAgent:
def _configure_logging(self, verbose: Union[bool, int]) -> None:
"""Configure logging levels."""
if isinstance(verbose, int) and verbose >= 10:
logging.getLogger("litellm").setLevel(logging.DEBUG)
get_logger("litellm").setLevel(logging.DEBUG)
else:
logging.getLogger("litellm").setLevel(logging.WARNING)
logging.getLogger("httpx").setLevel(logging.WARNING)
get_logger("litellm").setLevel(logging.WARNING)
get_logger("httpx").setLevel(logging.WARNING)
def _get_model_params(self, model: Optional[str] = None) -> Dict[str, Any]:
"""Build parameters for LiteLLM calls."""
File diff suppressed because it is too large. Load diff
@@ -15,6 +15,7 @@ from dataclasses import dataclass, field
from enum import Enum
import inspect
import logging
from praisonaiagents._logging import get_logger
import asyncio
import threading
import time
@@ -22,8 +23,7 @@ import time
if TYPE_CHECKING:
from .agent import Agent
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
class ContextPolicy(Enum):
"""Policy for context sharing during handoff."""
@@ -32,7 +32,6 @@ class ContextPolicy(Enum):
NONE = "none" # No context sharing
LAST_N = "last_n" # Share last N messages
@dataclass
class HandoffConfig:
"""
@@ -98,19 +97,16 @@ class HandoffConfig:
data["context_policy"] = ContextPolicy(data["context_policy"])
return cls(**{k: v for k, v in data.items() if k in cls.__dataclass_fields__})
class HandoffError(Exception):
"""Base exception for handoff errors."""
pass
class HandoffCycleError(HandoffError):
"""Raised when a cycle is detected in handoff chain."""
def __init__(self, chain: List[str]):
self.chain = chain
super().__init__(f"Handoff cycle detected: {' -> '.join(chain)}")
class HandoffDepthError(HandoffError):
"""Raised when max handoff depth is exceeded."""
def __init__(self, depth: int, max_depth: int):
@@ -118,7 +114,6 @@ class HandoffDepthError(HandoffError):
self.max_depth = max_depth
super().__init__(f"Max handoff depth exceeded: {depth} > {max_depth}")
class HandoffTimeoutError(HandoffError):
"""Raised when handoff times out."""
def __init__(self, timeout: float, agent_name: str):
@@ -126,41 +121,34 @@ class HandoffTimeoutError(HandoffError):
self.agent_name = agent_name
super().__init__(f"Handoff to {agent_name} timed out after {timeout}s")
# Thread-local storage for tracking handoff chains
_handoff_context = threading.local()
def _get_handoff_chain() -> List[str]:
"""Get current handoff chain from thread-local storage."""
if not hasattr(_handoff_context, 'chain'):
_handoff_context.chain = []
return _handoff_context.chain
def _get_handoff_depth() -> int:
"""Get current handoff depth."""
return len(_get_handoff_chain())
def _push_handoff(agent_name: str) -> None:
"""Push agent to handoff chain."""
chain = _get_handoff_chain()
chain.append(agent_name)
def _pop_handoff() -> Optional[str]:
"""Pop agent from handoff chain."""
chain = _get_handoff_chain()
return chain.pop() if chain else None
def _clear_handoff_chain() -> None:
"""Clear the handoff chain."""
if hasattr(_handoff_context, 'chain'):
_handoff_context.chain = []
@dataclass
class HandoffInputData:
"""Data passed to a handoff target agent."""
@@ -170,7 +158,6 @@ class HandoffInputData:
handoff_depth: int = 0
handoff_chain: List[str] = field(default_factory=list)
@dataclass
class HandoffResult:
"""Result of a handoff operation."""
@@ -671,7 +658,6 @@ class Handoff:
return handoff_tool
def handoff(
agent: 'Agent',
tool_name_override: Optional[str] = None,
@@ -760,7 +746,6 @@ def handoff(
config=config,
)
# Handoff filters - common patterns for filtering handoff data
class handoff_filters:
"""Common handoff input filters."""
@@ -827,14 +812,12 @@ class handoff_filters:
return data
# Recommended prompt prefix for agents that use handoffs
RECOMMENDED_PROMPT_PREFIX = """You have the ability to transfer tasks to specialized agents when appropriate.
When you determine that a task would be better handled by another agent with specific expertise,
use the transfer tool to hand off the task. The receiving agent will have the full context of
the conversation and will continue helping the user."""
def prompt_with_handoff_instructions(base_prompt: str, agent: 'Agent') -> str:
"""
Add handoff instructions to an agent's prompt.
@@ -14,13 +14,13 @@ Usage::
import asyncio
import logging
from praisonaiagents._logging import get_logger
import threading
import time
from dataclasses import dataclass, field
from typing import Any, Callable, Optional, Union
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
@dataclass
class HeartbeatConfig:
@@ -43,7 +43,6 @@ class HeartbeatConfig:
on_error: Union[str, Callable] = "retry"
max_retries: int = 3
class Heartbeat:
"""Standalone heartbeat coordinator.
@@ -7,6 +7,7 @@ from typing import Optional, Any, Dict, Union, List
from ..agent.agent import Agent
from pydantic import BaseModel, Field
import logging
from praisonaiagents._logging import get_logger
import warnings
# Filter out Pydantic warning about fields
warnings.filterwarnings("ignore", "Valid config keys have changed in V2", UserWarning)
@@ -77,10 +78,10 @@ class ImageAgent(Agent):
# Only suppress logs if not in debug mode
if not isinstance(verbose, bool) and verbose >= 10:
# Enable detailed debug logging
logging.getLogger("asyncio").setLevel(logging.DEBUG)
logging.getLogger("selector_events").setLevel(logging.DEBUG)
logging.getLogger("litellm.utils").setLevel(logging.DEBUG)
logging.getLogger("litellm.main").setLevel(logging.DEBUG)
get_logger("asyncio").setLevel(logging.DEBUG)
get_logger("selector_events").setLevel(logging.DEBUG)
get_logger("litellm.utils").setLevel(logging.DEBUG)
get_logger("litellm.main").setLevel(logging.DEBUG)
if hasattr(self, 'litellm'):
self.litellm.suppress_debug_messages = False
self.litellm.set_verbose = True
@@ -88,12 +89,12 @@ class ImageAgent(Agent):
warnings.resetwarnings()
else:
# Suppress debug logging for normal operation
logging.getLogger("asyncio").setLevel(logging.WARNING)
logging.getLogger("selector_events").setLevel(logging.WARNING)
logging.getLogger("litellm.utils").setLevel(logging.WARNING)
logging.getLogger("litellm.main").setLevel(logging.WARNING)
logging.getLogger("httpx").setLevel(logging.WARNING)
logging.getLogger("httpcore").setLevel(logging.WARNING)
get_logger("asyncio").setLevel(logging.WARNING)
get_logger("selector_events").setLevel(logging.WARNING)
get_logger("litellm.utils").setLevel(logging.WARNING)
get_logger("litellm.main").setLevel(logging.WARNING)
get_logger("httpx").setLevel(logging.WARNING)
get_logger("httpcore").setLevel(logging.WARNING)
if hasattr(self, 'litellm'):
self.litellm.suppress_debug_messages = True
self.litellm._logging._disable_debugging()
@@ -23,12 +23,12 @@ from __future__ import annotations
import hashlib
import json
import logging
from praisonaiagents._logging import get_logger
import time
from dataclasses import dataclass, field
from typing import Any, Dict, List, Literal, Optional, TypedDict
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
# ---------------------------------------------------------------------------
# Configuration
@@ -61,7 +61,6 @@ class LoopDetectionConfig:
if self.critical_threshold <= self.warn_threshold:
self.critical_threshold = self.warn_threshold + 1
# ---------------------------------------------------------------------------
# Result type
# ---------------------------------------------------------------------------
@@ -73,10 +72,8 @@ class LoopDetectionResult(TypedDict, total=False):
message: Optional[str]
count: int
_NOT_STUCK: LoopDetectionResult = {"stuck": False}
# ---------------------------------------------------------------------------
# History record
# ---------------------------------------------------------------------------
@@ -87,7 +84,6 @@ class ToolCallRecord(TypedDict, total=False):
result_hash: Optional[str]
timestamp: float
# ---------------------------------------------------------------------------
# Hashing helpers
# ---------------------------------------------------------------------------
@@ -108,11 +104,9 @@ def _stable_json(value: Any) -> str:
except Exception:
return '"<unserializable>"'
def _sha256_hex(text: str, prefix_len: int = 16) -> str:
return hashlib.sha256(text.encode("utf-8", errors="replace")).hexdigest()[:prefix_len]
def hash_tool_call(tool_name: str, args: Any) -> str:
"""
Compute a stable hash for a (tool_name, args) pair.
@@ -127,7 +121,6 @@ def hash_tool_call(tool_name: str, args: Any) -> str:
stable = _stable_json({"t": tool_name, "a": args})
return _sha256_hex(stable)
def _hash_result(result: Any) -> Optional[str]:
"""Hash a tool result for no-progress detection."""
if result is None:
@@ -138,7 +131,6 @@ def _hash_result(result: Any) -> Optional[str]:
except Exception:
return None
# ---------------------------------------------------------------------------
# Record tool call / outcome
# ---------------------------------------------------------------------------
@@ -169,7 +161,6 @@ def record_tool_call(
if len(history) > max_size:
del history[: len(history) - max_size]
def record_tool_outcome(
history: List[ToolCallRecord],
tool_name: str,
@@ -204,7 +195,6 @@ def record_tool_outcome(
)
return
# ---------------------------------------------------------------------------
# Detectors
# ---------------------------------------------------------------------------
@@ -215,7 +205,6 @@ def _known_poll_tool(tool_name: str) -> bool:
name_lower = tool_name.lower()
return any(kw in name_lower for kw in _poll_keywords)
def _count_generic_repeat(
history: List[ToolCallRecord],
args_hash: str,
@@ -227,7 +216,6 @@ def _count_generic_repeat(
if rec["tool_name"] == tool_name and rec["args_hash"] == args_hash
)
def _no_progress_streak(
history: List[ToolCallRecord],
args_hash: str,
@@ -256,7 +244,6 @@ def _no_progress_streak(
return streak
def _ping_pong_streak(
history: List[ToolCallRecord],
current_hash: str,
@@ -293,7 +280,6 @@ def _ping_pong_streak(
return count + 1 # include current call
# ---------------------------------------------------------------------------
# Main detection function
# ---------------------------------------------------------------------------
@@ -0,0 +1,600 @@
"""
Memory, caching, and session persistence mixin for the Agent class.
Contains all methods for chat history management, caching, session
persistence, auto-memory, and auto-learning. Extracted from agent.py
for maintainability.
"""
import os
import logging
from praisonaiagents._logging import get_logger
# Fallback helpers to avoid circular imports
def _get_console():
from rich.console import Console
return Console
def _get_live():
from rich.live import Live
return Live
def _get_display_functions():
from ..main import (
display_error, display_instruction, display_interaction,
display_generating, display_self_reflection, ReflectionOutput,
adisplay_instruction, execute_sync_callback
)
return {
'display_error': display_error,
'display_instruction': display_instruction,
'display_interaction': display_interaction,
'display_generating': display_generating,
'display_self_reflection': display_self_reflection,
'ReflectionOutput': ReflectionOutput,
'adisplay_instruction': adisplay_instruction,
'execute_sync_callback': execute_sync_callback,
}
logger = logging.getLogger(__name__)
import contextlib
from typing import List, Optional, Any, Dict, Generator, TYPE_CHECKING
from collections import OrderedDict
if TYPE_CHECKING:
pass
class MemoryMixin:
"""Mixin providing memory methods for the Agent class."""
def _cache_put(self, cache_dict, key, value):
"""Thread-safe LRU cache put operation.
Args:
cache_dict: The cache dictionary (OrderedDict)
key: Cache key
value: Value to cache
"""
with self._cache_lock:
# Move to end if already exists (LRU update)
if key in cache_dict:
del cache_dict[key]
# Add new entry
cache_dict[key] = value
# Evict oldest if over limit
while len(cache_dict) > self._max_cache_size:
cache_dict.popitem(last=False) # Remove oldest (FIFO)
def _add_to_chat_history(self, role, content):
"""Thread-safe method to add messages to chat history.
Args:
role: Message role ("user", "assistant", "system")
content: Message content
"""
with self._history_lock:
self.chat_history.append({"role": role, "content": content})
def _add_to_chat_history_if_not_duplicate(self, role, content):
"""Thread-safe method to add messages to chat history only if not duplicate.
Atomically checks for duplicate and adds message under the same lock to prevent TOCTOU races.
Args:
role: Message role ("user", "assistant", "system")
content: Message content
Returns:
bool: True if message was added, False if duplicate was detected
"""
with self._history_lock:
# Check for duplicate within the same critical section
if (self.chat_history and
self.chat_history[-1].get("role") == role and
self.chat_history[-1].get("content") == content):
return False
# Not a duplicate, add the message
self.chat_history.append({"role": role, "content": content})
return True
def _get_chat_history_length(self):
"""Thread-safe method to get chat history length."""
with self._history_lock:
return len(self.chat_history)
def _truncate_chat_history(self, length):
"""Thread-safe method to truncate chat history to specified length.
Args:
length: Target length for chat history
"""
with self._history_lock:
self.chat_history = self.chat_history[:length]
def _cache_get(self, cache_dict, key):
"""Thread-safe LRU cache get operation.
Args:
cache_dict: The cache dictionary (OrderedDict)
key: Cache key
Returns:
Value if found, None otherwise
"""
with self._cache_lock:
if key not in cache_dict:
return None
# Move to end (mark as recently used)
value = cache_dict[key]
del cache_dict[key]
cache_dict[key] = value
return value
def clear_history(self):
"""Clear all chat history.
Also resets _auto_save_last_index to prevent silent message loss
when auto_save is enabled.
"""
self.chat_history = []
# Reset auto-save index to prevent stale index causing message loss
self._auto_save_last_index = 0
def prune_history(self, keep_last: int = 5) -> int:
"""
Prune chat history to keep only the last N messages.
Useful for cleaning up large history after image analysis sessions
to prevent context window saturation.
Args:
keep_last: Number of recent messages to keep
Returns:
Number of messages deleted
"""
with self._history_lock:
if len(self.chat_history) <= keep_last:
return 0
deleted_count = len(self.chat_history) - keep_last
self.chat_history = self.chat_history[-keep_last:]
# Reset auto-save index to match new history length
self._auto_save_last_index = len(self.chat_history)
return deleted_count
def delete_history(self, index: int) -> bool:
"""
Delete a specific message from chat history by index.
Supports negative indexing (-1 for last message, etc.).
Args:
index: Message index (0-based, supports negative indexing)
Returns:
True if deleted, False if index out of range
"""
with self._history_lock:
try:
del self.chat_history[index]
# Adjust auto-save index if deletion affects saved range
if hasattr(self, '_auto_save_last_index'):
self._auto_save_last_index = min(
self._auto_save_last_index,
len(self.chat_history)
)
return True
except IndexError:
return False
def delete_history_matching(self, pattern: str) -> int:
"""
Delete all messages matching a pattern.
Useful for removing all image-related messages after processing.
Args:
pattern: Substring to match in message content
Returns:
Number of messages deleted
"""
with self._history_lock:
original_len = len(self.chat_history)
self.chat_history = [
msg for msg in self.chat_history
if pattern.lower() not in msg.get("content", "").lower()
]
deleted_count = original_len - len(self.chat_history)
# Adjust auto-save index if deletion affects saved range
if deleted_count > 0 and hasattr(self, '_auto_save_last_index'):
self._auto_save_last_index = min(
self._auto_save_last_index,
len(self.chat_history)
)
return deleted_count
def get_history_size(self) -> int:
"""Get the current number of messages in chat history."""
return len(self.chat_history)
@contextlib.contextmanager
def ephemeral(self) -> Generator[None, None, None]:
"""
Context manager for ephemeral conversations.
Messages within this block are NOT permanently stored in chat_history.
History is restored to pre-block state after exiting.
Example:
with agent.ephemeral():
response = agent.chat("[IMAGE] Analyze this")
# After block, history is restored - image NOT persisted
"""
# Save current history state
with self._history_lock:
saved_history = self.chat_history.copy()
try:
yield
finally:
# Restore history to pre-block state
with self._history_lock:
self.chat_history = saved_history
def _init_db_session(self):
"""Initialize DB session if db adapter is provided (lazy, first chat only)."""
if self._db is None or self._db_initialized:
return
# Generate session_id if not provided: default to per-hour ID (YYYYMMDDHH-agentname)
if self._session_id is None:
import hashlib
from datetime import datetime, timezone
# Per-hour session ID: YYYYMMDDHH (UTC) + agent name hash for uniqueness
hour_str = datetime.now(timezone.utc).strftime("%Y%m%d%H")
agent_hash = hashlib.md5((self.name or "agent").encode()).hexdigest()[:6]
self._session_id = f"{hour_str}-{agent_hash}"
# Call db adapter's on_agent_start to get previous messages
try:
history = self._db.on_agent_start(
agent_name=self.name,
session_id=self._session_id,
user_id=self.user_id,
metadata={"role": self.role, "goal": self.goal}
)
# Restore chat history from previous session
if history:
for msg in history:
self.chat_history.append({
"role": msg.role,
"content": msg.content
})
logging.info(f"Resumed session {self._session_id} with {len(history)} messages")
except Exception as e:
logging.warning(f"Failed to initialize DB session: {e}")
self._db_initialized = True
self._current_run_id = None # Track current run
def _init_session_store(self):
"""
Initialize session store for JSON-based persistence (lazy, first chat only).
This is used when session_id is provided but no DB adapter.
Enables automatic session persistence with zero configuration.
"""
if self._session_store_initialized:
return
# Only initialize if session_id is provided and no DB adapter
if self._session_id is None or self._db is not None:
self._session_store_initialized = True
return
try:
from ..session import get_default_session_store
self._session_store = get_default_session_store()
# Restore chat history from previous session
history = self._session_store.get_chat_history(self._session_id)
if history:
# Only restore if chat_history is empty (avoid duplicates)
if not self.chat_history:
for msg in history:
self.chat_history.append({
"role": msg["role"],
"content": msg["content"]
})
logging.info(f"Restored session {self._session_id} with {len(history)} messages from JSON store")
# Set agent info
self._session_store.set_agent_info(
self._session_id,
agent_name=self.name,
user_id=self.user_id,
)
except Exception as e:
logging.warning(f"Failed to initialize session store: {e}")
self._session_store = None
self._session_store_initialized = True
def _start_run(self, input_content: str):
"""Start a new run (turn) for persistence tracking."""
if self._db is None:
return
import uuid
self._current_run_id = f"run-{uuid.uuid4().hex[:12]}"
try:
if hasattr(self._db, 'on_run_start'):
self._db.on_run_start(
session_id=self._session_id,
run_id=self._current_run_id,
input_content=input_content,
metadata={"agent_name": self.name}
)
except Exception as e:
logging.warning(f"Failed to start run: {e}")
def _end_run(self, output_content: str, status: str = "completed", metrics: dict = None):
"""End the current run (turn)."""
if self._db is None or self._current_run_id is None:
return
try:
if hasattr(self._db, 'on_run_end'):
self._db.on_run_end(
session_id=self._session_id,
run_id=self._current_run_id,
output_content=output_content,
status=status,
metrics=metrics or {},
metadata={"agent_name": self.name}
)
except Exception as e:
logging.warning(f"Failed to end run: {e}")
self._current_run_id = None
def _persist_message(self, role: str, content: str):
"""Persist a message to the DB or session store."""
# Try DB adapter first
if self._db is not None:
try:
if role == "user":
self._db.on_user_message(self._session_id, content)
elif role == "assistant":
self._db.on_agent_message(self._session_id, content)
except Exception as e:
logging.warning(f"Failed to persist message to DB: {e}")
return
# Fall back to session store (JSON-based)
if self._session_store is not None and self._session_id is not None:
try:
if role == "user":
self._session_store.add_user_message(self._session_id, content)
elif role == "assistant":
self._session_store.add_assistant_message(self._session_id, content)
except Exception as e:
logging.warning(f"Failed to persist message to session store: {e}")
def session_id(self) -> Optional[str]:
"""Get the current session ID."""
return self._session_id
def _load_history_context(self):
"""Load history from past sessions into context.
Note: This functionality is now handled via context= param with ManagerConfig.
This method is kept for backward compatibility but is a no-op.
Use context=ManagerConfig(history_sessions=N) to load past sessions.
"""
pass
def _process_auto_memory(self, user_message: str, assistant_response: str):
"""Process auto-memory extraction after agent response.
Called after each agent response when auto_memory=True in MemoryConfig.
Uses AutoMemory to extract and store memorable content (names, preferences,
facts) from the conversation. No-op when auto_memory is disabled.
Args:
user_message: The user's input message
assistant_response: The agent's response
"""
if not self._auto_memory or not self._memory_instance:
return
try:
from ..memory.auto_memory import AutoMemory
# Lazy-create AutoMemory wrapper on first use
if not hasattr(self, '_auto_memory_instance') or self._auto_memory_instance is None:
self._auto_memory_instance = AutoMemory(
self._memory_instance,
enabled=True,
verbose=1 if getattr(self, 'verbose', False) else 0
)
self._auto_memory_instance.process_interaction(
user_message=str(user_message),
assistant_response=str(assistant_response),
)
except Exception as e:
logging.debug(f"Auto-memory extraction failed: {e}")
def _process_auto_learning(self):
"""Process auto-learning extraction after agent response.
Called after each agent response when LearnMode.AGENTIC is set.
Uses LearnManager.process_conversation() to extract and store learnings
(persona, insights, patterns) from the conversation. No-op when learning
is disabled or mode is not AGENTIC.
"""
# Quick exit if no learn config or mode is not AGENTIC
if not self._learn_config:
return
# Check if mode is AGENTIC (auto-extract learnings)
from ..memory.learn.protocols import LearnMode
mode = getattr(self._learn_config, 'mode', None)
# Handle PROPOSE mode — extract but store as pending for user approval
if (isinstance(mode, LearnMode) and mode == LearnMode.PROPOSE) or \
(isinstance(mode, str) and mode == 'propose'):
learn_manager = None
if self._memory_instance and hasattr(self._memory_instance, 'learn'):
learn_manager = self._memory_instance.learn
if learn_manager:
try:
recent_messages = self.chat_history[-2:] if len(self.chat_history) >= 2 else self.chat_history
if recent_messages:
# Use same extraction as AGENTIC, but don't auto-store
result = learn_manager.process_conversation(
messages=recent_messages,
llm=getattr(self._learn_config, 'llm', None) or self.llm,
extract_only=True,
)
# Move extracted items to pending queue
if result:
for p in result.get("persona", []):
if p:
learn_manager.add_pending(p, category="persona")
for i in result.get("insights", []):
if i:
learn_manager.add_pending(i, category="insights")
for pt in result.get("patterns", []):
if pt:
learn_manager.add_pending(pt, category="patterns")
except Exception as e:
logging.debug(f"PROPOSE mode learning extraction failed: {e}")
return
if mode is None or (isinstance(mode, LearnMode) and mode != LearnMode.AGENTIC):
return
if isinstance(mode, str) and mode != 'agentic':
return
# Get LearnManager from memory instance
learn_manager = None
if self._memory_instance and hasattr(self._memory_instance, 'learn'):
learn_manager = self._memory_instance.learn
if not learn_manager:
return
try:
# Process recent conversation (last 2 messages: user + assistant)
recent_messages = self.chat_history[-2:] if len(self.chat_history) >= 2 else self.chat_history
if recent_messages:
learn_manager.process_conversation(
messages=recent_messages,
llm=getattr(self._learn_config, 'llm', None) or self.llm,
)
except Exception as e:
logging.debug(f"Auto-learning extraction failed: {e}")
def _auto_save_session(self):
"""Auto-save session if auto_save is enabled.
G-1 FIX: Routes to SessionStore instead of Memory.save_session() to
maintain clean separation between conversation history (SessionStore)
and semantic memory (Memory).
Issue 1 FIX: Track last saved index to avoid duplicate insertion when
called multiple times in the same session.
"""
if not self.auto_save:
return
try:
# Filter out history markers before saving
clean_history = [
{k: v for k, v in msg.items() if k != "_from_history"}
for msg in self.chat_history
]
# Issue 1 FIX: Only save NEW messages since last save
# Track last saved index to avoid duplicates
last_saved = getattr(self, '_auto_save_last_index', 0)
new_messages = clean_history[last_saved:]
if not new_messages:
return # Nothing new to save
# G-1 FIX: Use SessionStore for conversation history persistence
# This maintains clean separation: Memory = facts, SessionStore = turns
if self._session_store is not None:
# Persist only NEW messages to SessionStore
for msg in new_messages:
self._session_store.add_message(
self.auto_save, # Use auto_save name as session_id
role=msg.get("role", "user"),
content=msg.get("content", ""),
)
# Update last saved index
self._auto_save_last_index = len(clean_history)
logging.debug(f"Auto-saved {len(new_messages)} new messages to SessionStore: {self.auto_save}")
elif self._memory_instance and hasattr(self._memory_instance, 'save_session'):
# Fallback to Memory.save_session() for backward compatibility
# Memory.save_session() replaces entire history, so no duplicate issue
self._memory_instance.save_session(
name=self.auto_save,
conversation_history=clean_history,
metadata={"agent_name": self.name, "user_id": self.user_id}
)
logging.debug(f"Auto-saved session to Memory: {self.auto_save}")
except Exception as e:
logging.debug(f"Error auto-saving session: {e}")
def _save_output_to_file(self, content: str) -> bool:
"""Save agent output to file if output_file is configured.
Args:
content: The response content to save
Returns:
True if file was saved, False otherwise
"""
if not self._output_file:
return False
try:
import os
# Expand user home directory and resolve path
file_path = os.path.expanduser(self._output_file)
file_path = os.path.abspath(file_path)
# Create parent directories if they don't exist
parent_dir = os.path.dirname(file_path)
if parent_dir and not os.path.exists(parent_dir):
os.makedirs(parent_dir, exist_ok=True)
# Write content to file
with open(file_path, 'w', encoding='utf-8') as f:
f.write(str(content))
# Print success message to terminal
print(f"✅ Output saved to {file_path}")
logging.debug(f"Output saved to file: {file_path}")
return True
except Exception as e:
logging.warning(f"Failed to save output to file '{self._output_file}': {e}")
print(f"⚠️ Failed to save output to {self._output_file}: {e}")
return False
@@ -9,12 +9,12 @@ import threading
import heapq
import time
import logging
from praisonaiagents._logging import get_logger
from typing import Optional, Any, List, Tuple
from dataclasses import dataclass, field
from enum import Enum
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
class MessagePriority(Enum):
"""Message priority levels."""
@@ -23,7 +23,6 @@ class MessagePriority(Enum):
HIGH = 10
URGENT = 20
@dataclass(order=True)
class QueuedMessage:
"""A message in the queue with priority and timestamp."""
@@ -36,7 +35,6 @@ class QueuedMessage:
# Negate priority for max-heap behavior (higher priority = lower number in heap)
self.priority = -self.priority
class AgentMessageQueue:
"""
Thread-safe message queue for agent prompts.
@@ -158,7 +156,6 @@ class AgentMessageQueue:
"""Total number of messages ever enqueued."""
return self._message_count
class AsyncAgentMessageQueue:
"""
Async-compatible message queue for agent prompts.
@@ -9,6 +9,7 @@ Follows the Agent() class patterns:
"""
import os
import logging
from praisonaiagents._logging import get_logger
import warnings
from dataclasses import dataclass
from typing import Optional, Any, Dict, Union, List
@@ -16,7 +17,6 @@ from pathlib import Path
warnings.filterwarnings("ignore", "Valid config keys have changed in V2", UserWarning)
@dataclass
class OCRConfig:
"""Configuration for OCR settings."""
@@ -38,7 +38,6 @@ class OCRConfig:
"api_key": self.api_key,
}
class OCRAgent:
"""
A specialized agent for OCR (Optical Character Recognition).
@@ -143,10 +142,10 @@ class OCRAgent:
def _configure_logging(self, verbose: Union[bool, int]) -> None:
"""Configure logging levels."""
if isinstance(verbose, int) and verbose >= 10:
logging.getLogger("litellm").setLevel(logging.DEBUG)
get_logger("litellm").setLevel(logging.DEBUG)
else:
logging.getLogger("litellm").setLevel(logging.WARNING)
logging.getLogger("httpx").setLevel(logging.WARNING)
get_logger("litellm").setLevel(logging.WARNING)
get_logger("httpx").setLevel(logging.WARNING)
def _get_model_params(self, model: Optional[str] = None) -> Dict[str, Any]:
"""Build parameters for LiteLLM calls."""
@@ -34,6 +34,7 @@ Example:
"""
import logging
from praisonaiagents._logging import get_logger
from typing import List, Optional, Any, Dict
from dataclasses import dataclass, field
from enum import Enum
@@ -47,7 +48,6 @@ class ExpandStrategy(Enum):
CREATIVE = "creative"
AUTO = "auto"
@dataclass
class ExpandResult:
"""Result of a prompt expansion operation."""
@@ -59,7 +59,6 @@ class ExpandResult:
def __repr__(self):
return f"ExpandResult(strategy={self.strategy_used.value}, original_len={len(self.original_prompt)}, expanded_len={len(self.expanded_prompt)})"
class PromptExpanderAgent:
"""
Agent for expanding short prompts into detailed, comprehensive prompts.
@@ -213,7 +212,7 @@ Expanded prompt:"""
self._agent = None # Lazy initialized
# Setup logging
self.logger = logging.getLogger(__name__)
self.logger = get_logger(__name__)
if self.verbose:
self.logger.setLevel(logging.DEBUG)
@@ -39,12 +39,12 @@ Example:
"""
import logging
from praisonaiagents._logging import get_logger
import json
from typing import List, Optional, Any, Dict
from dataclasses import dataclass, field
from enum import Enum
class RewriteStrategy(Enum):
"""Enumeration of available query rewriting strategies."""
BASIC = "basic"
@@ -55,7 +55,6 @@ class RewriteStrategy(Enum):
CONTEXTUAL = "contextual"
AUTO = "auto"
@dataclass
class RewriteResult:
"""Result of a query rewriting operation."""
@@ -86,7 +85,6 @@ class RewriteResult:
queries.extend(self.sub_queries)
return list(set(queries)) # Remove duplicates
class QueryRewriterAgent:
"""
Agent for rewriting queries to improve retrieval quality in RAG applications.
@@ -271,7 +269,7 @@ Improved version:"""
}
# Setup logging
self.logger = logging.getLogger(__name__)
self.logger = get_logger(__name__)
if self.verbose:
self.logger.setLevel(logging.DEBUG)
@@ -4,7 +4,7 @@ from dataclasses import dataclass, field, asdict
from typing import Any, Callable, Dict, List, Optional, Union
import asyncio
import logging
from praisonaiagents._logging import get_logger
@dataclass
class RealtimeConfig:
@@ -33,7 +33,6 @@ class RealtimeConfig:
"""Convert config to dictionary."""
return {k: v for k, v in asdict(self).items() if v is not None}
class RealtimeAgent:
"""Agent for real-time voice conversations using OpenAI Realtime API.
@@ -107,7 +106,7 @@ class RealtimeAgent:
self._connected = False
# Configure logging
self._logger = logging.getLogger(f"RealtimeAgent.{name}")
self._logger = get_logger(f"RealtimeAgent.{name}")
if not verbose:
self._logger.setLevel(logging.WARNING)
@@ -7,14 +7,14 @@ model selection based on task characteristics.
import os
import logging
from praisonaiagents._logging import get_logger
from typing import Dict, List, Optional, Any, Union
from .agent import Agent
from ..llm.model_router import ModelRouter
from ..llm import LLM, TokenUsage
from ..trace.protocol import get_default_emitter
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
class RouterAgent(Agent):
"""
@@ -1,88 +1,159 @@
"""
Session and persistence management functionality for Agent class.
Session manager mixin for the Agent class.
This module contains methods related to session management, persistence, and state handling.
Split from the main agent.py file for better maintainability.
Contains session management, persistence, and state coordination.
Extracted from agent.py for better modularity and maintainability.
"""
import logging
import os
from typing import Any, Dict, List, Optional, Union
import time
import logging
from typing import Optional, Any, Dict, List, TYPE_CHECKING
if TYPE_CHECKING:
pass
logger = logging.getLogger(__name__)
class SessionManagerMixin:
"""Mixin class containing session management methods for the Agent class."""
"""Mixin providing session management methods for the Agent class.
@property
def session_id(self) -> Optional[str]:
"""Get the current session ID."""
return getattr(self, '_session_id', None)
This mixin handles session lifecycle, persistence, and state coordination
while keeping session logic separate from other agent concerns.
"""
def _init_db_session(self) -> None:
"""Initialize database session for persistent storage."""
# Session initialization logic would go here
# This is extracted from the main agent.py file
raise NotImplementedError("Database session initialization moved from main Agent class")
def _init_session_store(self) -> None:
"""Initialize session store for state persistence."""
# Session store initialization logic would go here
raise NotImplementedError("Session store initialization moved from main Agent class")
def _start_run(self, input_content: str) -> None:
"""Start a new run/session with input tracking."""
# Logic to start a new execution run
logging.info(f"{self.name}: Starting new run with input: {input_content[:100]}...")
def _initialize_session(self, session_id: Optional[str] = None) -> str:
"""Initialize a new session or resume an existing one.
def _end_run(self, output_content: str, status: str = "completed",
metrics: Optional[Dict[str, Any]] = None) -> None:
"""End the current run with output tracking."""
# Logic to end the current execution run
logging.info(f"{self.name}: Ending run with status: {status}")
Args:
session_id: Optional session ID to resume
Returns:
The session ID (new or existing)
"""
if session_id:
logger.debug(f"Resuming session: {session_id}")
return session_id
def _persist_message(self, role: str, content: str) -> None:
"""Persist a message to the session store."""
# Logic to persist messages
if hasattr(self, 'chat_history'):
self.chat_history.append({"role": role, "content": content})
# Generate new session ID
timestamp = int(time.time())
agent_name = (getattr(self, 'name', None) or 'agent').lower().replace(' ', '_')
new_session_id = f"{agent_name}_{timestamp}"
logger.debug(f"Initialized new session: {new_session_id}")
return new_session_id
def _auto_save_session(self) -> None:
"""Auto-save the current session state."""
# Auto-save logic would go here
if hasattr(self, '_auto_save_enabled') and self._auto_save_enabled:
logging.debug(f"{self.name}: Auto-saving session")
def _save_session_state(self, session_id: str, state: Dict[str, Any]) -> bool:
"""Save session state to persistent storage.
Args:
session_id: Session identifier
state: State dictionary to save
Returns:
True if saved successfully, False otherwise
"""
try:
# This is a placeholder implementation
# In practice, this would integrate with the actual session store
logger.debug(f"Saving session state for {session_id}: {len(state)} keys")
return True
except Exception as e:
logger.error(f"Failed to save session state: {e}")
return False
def _load_history_context(self) -> str:
"""Load historical context from previous sessions."""
# Logic to load context from previous sessions
return ""
def _load_session_state(self, session_id: str) -> Optional[Dict[str, Any]]:
"""Load session state from persistent storage.
Args:
session_id: Session identifier
Returns:
State dictionary if found, None otherwise
"""
try:
# This is a placeholder implementation
# In practice, this would integrate with the actual session store
logger.debug(f"Loading session state for {session_id}")
return {} # Return empty state as placeholder
except Exception as e:
logger.error(f"Failed to load session state: {e}")
return None
def _process_auto_memory(self, user_message: str, assistant_response: str) -> None:
"""Process and store automatic memory based on conversation."""
# Auto-memory processing logic
if hasattr(self, '_memory_instance') and self._memory_instance:
try:
# Store interaction in memory
memory_content = f"User: {user_message}\nAssistant: {assistant_response}"
self._memory_instance.store_short_term(memory_content)
logging.debug(f"{self.name}: Stored interaction in auto-memory")
except Exception as e:
logging.warning(f"Failed to store auto-memory: {e}")
def _cleanup_session(self, session_id: str) -> bool:
"""Clean up session resources and optionally persist final state.
Args:
session_id: Session identifier
Returns:
True if cleaned up successfully, False otherwise
"""
try:
logger.debug(f"Cleaning up session: {session_id}")
# Perform any necessary cleanup
# This might include saving final state, closing resources, etc.
return True
except Exception as e:
logger.error(f"Failed to cleanup session: {e}")
return False
def _process_auto_learning(self) -> None:
"""Process automatic learning from recent interactions."""
# Auto-learning processing logic
if hasattr(self, '_learn_enabled') and self._learn_enabled:
logging.debug(f"{self.name}: Processing auto-learning")
def _validate_session_state(self, state: Dict[str, Any]) -> bool:
"""Validate session state structure and content.
Args:
state: State dictionary to validate
Returns:
True if valid, False otherwise
"""
if not isinstance(state, dict):
logger.warning("Session state must be a dictionary")
return False
# Add any specific validation logic here
required_keys = [] # Define required keys if needed
for key in required_keys:
if key not in state:
logger.warning(f"Session state missing required key: {key}")
return False
return True
def _save_output_to_file(self, content: str) -> bool:
"""Save output content to a file if configured."""
# File output saving logic
if hasattr(self, '_output_file') and self._output_file:
try:
with open(self._output_file, 'a', encoding='utf-8') as f:
f.write(content + '\n')
return True
except Exception as e:
logging.error(f"Failed to save output to file: {e}")
return False
def _get_session_metadata(self, session_id: str) -> Dict[str, Any]:
"""Get metadata about a session.
Args:
session_id: Session identifier
Returns:
Metadata dictionary
"""
return {
'session_id': session_id,
'agent_name': getattr(self, 'name', None) or 'Agent',
'created_at': time.time(),
'last_accessed': time.time(),
}
def _merge_session_context(self, current_context: Dict[str, Any],
session_context: Dict[str, Any]) -> Dict[str, Any]:
"""Merge current context with session context.
Args:
current_context: Current request context
session_context: Stored session context
Returns:
Merged context dictionary
"""
# Start with session context as base
merged = session_context.copy() if session_context else {}
# Override with current context (current takes precedence)
merged.update(current_context)
return merged
@@ -6,11 +6,11 @@ Reuses existing telemetry/token_collector for token tracking.
"""
import logging
from praisonaiagents._logging import get_logger
from typing import Optional, List, Dict, Any, Callable
from dataclasses import dataclass, field
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
@dataclass
class SummarizationConfig:
@@ -22,7 +22,6 @@ class SummarizationConfig:
preserve_system: bool = True # Keep system message
preserve_recent: int = 2 # Keep last N message pairs
class SummarizationManager:
"""
Manages automatic conversation summarization.
@@ -180,7 +179,6 @@ SUMMARY:"""
"""Number of times summarization has been performed."""
return self._summarization_count
async def summarize_conversation(
messages: List[Dict[str, str]],
llm_call: Callable,
@@ -210,7 +208,6 @@ async def summarize_conversation(
return new_history
def summarize_conversation_sync(
messages: List[Dict[str, str]],
llm_call: Callable,
@@ -1,8 +1,9 @@
"""
Tool execution functionality for Agent class.
Tool execution mixin for the Agent class.
This module contains methods related to tool execution, validation, and calling.
Split from the main agent.py file for better maintainability.
Contains all methods for tool resolution, execution, approval,
cost tracking, and hook integration. Extracted from agent.py
for maintainability.
"""
import os
@@ -10,13 +11,98 @@ import time
import json
import logging
import asyncio
import inspect
import concurrent.futures
from typing import Any, Dict, List, Optional, Union
from typing import List, Optional, Any, Dict, Union, TYPE_CHECKING
if TYPE_CHECKING:
pass
class ToolExecutionMixin:
"""Mixin class containing tool execution methods for the Agent class."""
"""Mixin providing toolexecution methods for the Agent class."""
def _resolve_tool_names(self, tool_names):
"""Resolve tool names to actual tool instances from registry.
Args:
tool_names: List of tool name strings
Returns:
List of resolved tool instances
"""
resolved = []
try:
from ..tools.registry import get_registry
registry = get_registry()
for name in tool_names:
tool = registry.get(name)
if tool is not None:
resolved.append(tool)
else:
logging.warning(f"Tool '{name}' not found in registry")
except ImportError:
logging.warning("Tool registry not available, cannot resolve tool names")
return resolved
def _cast_arguments(self, func, arguments):
"""Cast arguments to their expected types based on function signature."""
if not callable(func) or not arguments:
return arguments
try:
sig = inspect.signature(func)
valid_params = set(sig.parameters.keys()) - {'self'}
casted_args = {}
# Sanitize argument names: strip trailing '=', whitespace, and
# other invalid chars that LLMs sometimes hallucinate in kwarg names
sanitized = {}
for raw_name, arg_value in arguments.items():
clean = raw_name.strip().rstrip('=').strip()
# If the cleaned name matches a valid param, use it;
# otherwise try case-insensitive match
if clean in valid_params:
sanitized[clean] = arg_value
elif clean.lower() in {p.lower() for p in valid_params}:
# Case-insensitive fuzzy match
matched = next(p for p in valid_params if p.lower() == clean.lower())
sanitized[matched] = arg_value
else:
sanitized[clean] = arg_value
arguments = sanitized
for param_name, arg_value in arguments.items():
if param_name in sig.parameters:
param = sig.parameters[param_name]
if param.annotation != inspect.Parameter.empty:
# Handle common type conversions
if param.annotation == int and isinstance(arg_value, (str, float)):
try:
casted_args[param_name] = int(float(arg_value))
except (ValueError, TypeError):
casted_args[param_name] = arg_value
elif param.annotation == float and isinstance(arg_value, (str, int)):
try:
casted_args[param_name] = float(arg_value)
except (ValueError, TypeError):
casted_args[param_name] = arg_value
elif param.annotation == bool and isinstance(arg_value, str):
casted_args[param_name] = arg_value.lower() in ('true', '1', 'yes', 'on')
else:
casted_args[param_name] = arg_value
else:
casted_args[param_name] = arg_value
else:
casted_args[param_name] = arg_value
return casted_args
except Exception as e:
logging.debug(f"Type casting failed for {getattr(func, '__name__', 'unknown function')}: {e}")
return arguments
def execute_tool(self, function_name: str, arguments: Dict[str, Any], tool_call_id: Optional[str] = None) -> Any:
"""
Execute a tool dynamically based on the function name and arguments.
@@ -47,9 +133,8 @@ class ToolExecutionMixin:
# Execute within injection context
return self._execute_tool_with_context(function_name, arguments, state, tool_call_id)
def _execute_tool_with_context(self, function_name: str, arguments: Dict[str, Any],
state: Any, tool_call_id: Optional[str] = None) -> Any:
def _execute_tool_with_context(self, function_name, arguments, state, tool_call_id=None):
"""Execute tool within injection context, with optional output truncation.
Args:
@@ -71,8 +156,8 @@ class ToolExecutionMixin:
# Emit TOOL_CALL_START to stream_emitter (for AIUI/AG-UI consumers)
# Zero overhead when no callbacks registered
if hasattr(self, '_Agent__stream_emitter') and self.__stream_emitter is not None and self.__stream_emitter.has_callbacks:
self.__stream_emitter.emit(StreamEvent(
if hasattr(self, '_Agent__stream_emitter') and getattr(self, "_Agent__stream_emitter", None) is not None and getattr(self, "_Agent__stream_emitter", None).has_callbacks:
getattr(self, "_Agent__stream_emitter", None).emit(StreamEvent(
type=StreamEventType.TOOL_CALL_START,
timestamp=_tool_start_perf,
tool_call={
@@ -118,16 +203,63 @@ class ToolExecutionMixin:
result = {"error": f"Tool timed out after {tool_timeout}s", "timeout": True}
else:
result = self._execute_tool_impl(function_name, arguments)
except Exception as e:
# Apply consistent error logging and formatting
error_msg = f"Error executing tool {function_name}: {str(e)}"
logging.error(error_msg)
result = {"error": error_msg}
# Trigger AFTER_TOOL hook and trace events
try:
from ..hooks import AfterToolInput
# Apply tool output truncation to prevent context overflow
# Uses context manager budget if enabled, otherwise applies default limit
if result:
try:
result_str = str(result)
if self.context_manager:
# Use context-aware truncation with configured budget
truncated = self._truncate_tool_output(function_name, result_str)
else:
# Apply default limit even without context management
# This prevents runaway tool outputs from causing overflow
if len(result_str) > DEFAULT_TOOL_OUTPUT_LIMIT:
# Use smart truncation format that judge recognizes as OK
tail_size = min(DEFAULT_TOOL_OUTPUT_LIMIT // 5, 2000)
head = result_str[:DEFAULT_TOOL_OUTPUT_LIMIT - tail_size]
tail = result_str[-tail_size:] if tail_size > 0 else ""
truncated = f"{head}\n...[{len(result_str):,} chars, showing first/last portions]...\n{tail}"
else:
truncated = result_str
if len(truncated) < len(result_str):
logging.debug(f"Truncated {function_name} output from {len(result_str)} to {len(truncated)} chars")
# For dicts, truncate large string fields (e.g., raw_content from search)
if isinstance(result, dict):
max_field_chars = DEFAULT_TOOL_OUTPUT_LIMIT if not self.context_manager else None
result = self._truncate_dict_fields(result, function_name, max_field_chars)
else:
result = truncated
except Exception as e:
logging.debug(f"Tool truncation skipped: {e}")
# Emit tool call end event (truncation handled by context_events.py)
_duration_ms = (_time.time() - _tool_start_time) * 1000
_trace_emitter.tool_call_end(self.name, function_name, str(result) if result else None, _duration_ms)
# Emit TOOL_CALL_RESULT to stream_emitter (for AIUI/AG-UI consumers)
# Zero overhead when no callbacks registered
if hasattr(self, '_Agent__stream_emitter') and getattr(self, "_Agent__stream_emitter", None) is not None and getattr(self, "_Agent__stream_emitter", None).has_callbacks:
# Truncate result for stream event (keep it reasonable for UI display)
result_summary = str(result)[:500] if result else None
getattr(self, "_Agent__stream_emitter", None).emit(StreamEvent(
type=StreamEventType.TOOL_CALL_RESULT,
timestamp=_time.perf_counter(),
tool_call={
"name": function_name,
"arguments": arguments,
"result": result_summary,
"id": tool_call_id, # Now properly threaded through
},
agent_id=self.name,
metadata={"duration_ms": _duration_ms},
))
# Trigger AFTER_TOOL hook
from ..hooks import HookEvent, AfterToolInput
after_tool_input = AfterToolInput(
session_id=getattr(self, '_session_id', 'default'),
cwd=os.getcwd(),
@@ -136,38 +268,508 @@ class ToolExecutionMixin:
agent_name=self.name,
tool_name=function_name,
tool_input=arguments,
tool_output=result
tool_output=result,
execution_time_ms=(_time.time() - _tool_start_time) * 1000
)
self._hook_runner.execute_sync(HookEvent.AFTER_TOOL, after_tool_input, target=function_name)
except Exception as hook_error:
logging.warning(f"Error in AFTER_TOOL hook: {hook_error}")
# G10 fix: Mark progress after successful tool execution
# This prevents false doom loop detection when tools succeed
if self._doom_loop_tracker is not None and result is not None:
is_error = isinstance(result, dict) and result.get('error')
if not is_error:
self._doom_loop_tracker.mark_progress(f"tool:{function_name}")
# Increment per-turn tool count for no-tool-call detection
self._autonomy_turn_tool_count = getattr(self, '_autonomy_turn_tool_count', 0) + 1
return result
except Exception as e:
# Emit tool call end with error
_duration_ms = (_time.time() - _tool_start_time) * 1000
_trace_emitter.tool_call_end(self.name, function_name, None, _duration_ms, str(e))
# Trigger OnError hook if needed (optional future step)
raise
# Emit TOOL_CALL_RESULT to stream_emitter
if hasattr(self, '_Agent__stream_emitter') and self.__stream_emitter is not None and self.__stream_emitter.has_callbacks:
self.__stream_emitter.emit(StreamEvent(
type=StreamEventType.TOOL_CALL_RESULT,
timestamp=_time.perf_counter(),
tool_call={
"name": function_name,
"arguments": arguments,
"id": tool_call_id,
"result": result,
},
agent_id=self.name,
))
def _trigger_after_agent_hook(self, prompt, response, start_time, tools_used=None):
"""Trigger AFTER_AGENT hook and return response."""
from ..hooks import HookEvent, AfterAgentInput
after_agent_input = AfterAgentInput(
session_id=getattr(self, '_session_id', 'default'),
cwd=os.getcwd(),
event_name=HookEvent.AFTER_AGENT,
timestamp=str(time.time()),
agent_name=self.name,
prompt=prompt if isinstance(prompt, str) else str(prompt),
response=response or "",
tools_used=tools_used or [],
total_tokens=0,
execution_time_ms=(time.time() - start_time) * 1000
)
self._hook_runner.execute_sync(HookEvent.AFTER_AGENT, after_agent_input)
# Emit trace event
_trace_emitter.tool_call_end(self.name, function_name, result, _time.time() - _tool_start_time)
# Auto-memory extraction (opt-in via MemoryConfig(auto_memory=True))
if response:
prompt_str = prompt if isinstance(prompt, str) else str(prompt)
self._process_auto_memory(prompt_str, str(response))
# Auto-learning extraction (opt-in via LearnConfig(mode=LearnMode.AGENTIC))
self._process_auto_learning()
return response
async def _atrigger_after_agent_hook(self, prompt, response, start_time, tools_used=None):
"""Async version: Trigger AFTER_AGENT hook and return response."""
from ..hooks import HookEvent, AfterAgentInput
after_agent_input = AfterAgentInput(
session_id=getattr(self, '_session_id', 'default'),
cwd=os.getcwd(),
event_name=HookEvent.AFTER_AGENT,
timestamp=str(time.time()),
agent_name=self.name,
prompt=prompt if isinstance(prompt, str) else str(prompt),
response=response or "",
tools_used=tools_used or [],
total_tokens=0,
execution_time_ms=(time.time() - start_time) * 1000
)
await self._hook_runner.execute(HookEvent.AFTER_AGENT, after_agent_input)
# Auto-memory extraction (opt-in via MemoryConfig(auto_memory=True))
if response:
prompt_str = prompt if isinstance(prompt, str) else str(prompt)
self._process_auto_memory(prompt_str, str(response))
# Auto-learning extraction (opt-in via LearnConfig(mode=LearnMode.AGENTIC))
self._process_auto_learning()
return response
def _calculate_llm_cost(self, prompt_tokens: int, completion_tokens: int, response: any = None) -> float:
"""Calculate estimated cost for LLM call.
Uses litellm for accurate pricing (1000+ models) when available,
falls back to built-in pricing table otherwise.
Args:
prompt_tokens: Number of tokens in the prompt
completion_tokens: Number of tokens in the completion
response: Optional LLM response object for more accurate cost calculation
Returns:
Estimated cost in USD
"""
from praisonaiagents.utils.cost_utils import calculate_llm_cost
return calculate_llm_cost(
prompt_tokens=prompt_tokens,
completion_tokens=completion_tokens,
model=self.llm,
response=response,
)
def _truncate_dict_fields(self, data: dict, tool_name: str, max_field_chars: int = None) -> dict:
"""Truncate large string fields in a dict to prevent context overflow."""
if max_field_chars is None:
# Use tool budget from context manager (default 5000 tokens * 4 chars/token = 20000 chars)
max_tokens = self.context_manager.get_tool_budget(tool_name) if self.context_manager else 5000
max_field_chars = max_tokens * 4
result = {}
for key, value in data.items():
if isinstance(value, str) and len(value) > max_field_chars:
# Smart truncate large string fields preserving head and tail
head_limit = int(max_field_chars * 0.8)
tail_limit = int(max_field_chars * 0.15)
head = value[:head_limit]
tail = value[-tail_limit:] if tail_limit > 0 else ""
result[key] = f"{head}\n...[{len(value):,} chars, showing first/last portions]...\n{tail}"
logging.debug(f"Smart truncated field '{key}' from {len(value)} to ~{max_field_chars} chars")
elif isinstance(value, dict):
result[key] = self._truncate_dict_fields(value, tool_name, max_field_chars)
elif isinstance(value, list):
result[key] = [
self._truncate_dict_fields(item, tool_name, max_field_chars) if isinstance(item, dict)
else (self._smart_truncate_str(item, max_field_chars) if isinstance(item, str) and len(item) > max_field_chars else item)
for item in value
]
else:
result[key] = value
return result
def _execute_tool_impl(self, function_name: str, arguments: Dict[str, Any]) -> Any:
"""Core tool execution implementation."""
# This method would contain the actual tool execution logic
# For now, just return a placeholder to demonstrate the pattern
raise NotImplementedError("Tool execution implementation moved from main Agent class")
async def execute_tool_async(self, function_name: str, arguments: Dict[str, Any]) -> Any:
"""Async tool execution for non-blocking operations."""
# Async version of execute_tool
raise NotImplementedError("Async tool execution implementation moved from main Agent class")
def _smart_truncate_str(self, text: str, max_chars: int) -> str:
"""Smart truncate a string preserving head and tail."""
if len(text) <= max_chars:
return text
head_limit = int(max_chars * 0.8)
tail_limit = int(max_chars * 0.15)
head = text[:head_limit]
tail = text[-tail_limit:] if tail_limit > 0 else ""
return f"{head}\n...[{len(text):,} chars, showing first/last portions]...\n{tail}"
def _resolve_approval_decision(self, tool_name: str, tool_args: dict, is_async: bool = False):
"""Shared approval logic for both sync and async paths.
Args:
tool_name: Name of the tool to check approval for
tool_args: Arguments to pass to the tool
is_async: Whether this is called from async context
Returns:
ApprovalDecision or coroutine: The approval decision (sync) or coroutine (async)
"""
from ..approval import get_approval_registry
from ..approval.protocols import ApprovalRequest, ApprovalDecision
from ..approval.registry import DEFAULT_DANGEROUS_TOOLS
backend = getattr(self, '_approval_backend', None)
approve_all = getattr(self, '_approve_all_tools', False)
if backend is not None:
needs_approval = approve_all or tool_name in DEFAULT_DANGEROUS_TOOLS
if needs_approval:
request = ApprovalRequest(
tool_name=tool_name,
arguments=tool_args,
risk_level=DEFAULT_DANGEROUS_TOOLS.get(tool_name, "medium"),
agent_name=getattr(self, 'name', None),
)
if is_async:
# Async path - return the coroutine for caller to await
cfg_timeout = getattr(self, '_approval_timeout', 0)
if cfg_timeout is None:
return backend.request_approval(request)
elif cfg_timeout > 0:
import asyncio
return asyncio.wait_for(
backend.request_approval(request),
timeout=cfg_timeout,
)
else:
return backend.request_approval(request)
else:
# Sync path - handle timeout and sync/async backend compatibility
cfg_timeout = getattr(self, '_approval_timeout', 0)
orig_timeout = None
if cfg_timeout is None:
orig_timeout = getattr(backend, '_timeout', None)
if orig_timeout is not None:
backend._timeout = 86400 * 365
elif cfg_timeout > 0:
orig_timeout = getattr(backend, '_timeout', None)
if orig_timeout is not None:
backend._timeout = cfg_timeout
try:
if hasattr(backend, 'request_approval_sync'):
return backend.request_approval_sync(request)
else:
# Use the shared utility to avoid code duplication and handle timeout correctly
from ..approval.utils import run_coroutine_safely
# Compute effective timeout from agent configuration
if cfg_timeout is None:
effective_timeout = None # indefinite wait
elif cfg_timeout > 0:
effective_timeout = cfg_timeout
else:
# cfg_timeout == 0: use backend default or fallback
effective_timeout = getattr(backend, '_timeout', 60)
return run_coroutine_safely(
backend.request_approval(request),
timeout=effective_timeout
)
finally:
if orig_timeout is not None and hasattr(backend, '_timeout'):
backend._timeout = orig_timeout
else:
if is_async:
# For async, wrap the decision in a coroutine
async def _async_approval():
return ApprovalDecision(approved=True, reason="Not a dangerous tool")
return _async_approval()
else:
return ApprovalDecision(approved=True, reason="Not a dangerous tool")
else:
if is_async:
return get_approval_registry().approve_async(
getattr(self, 'name', None), tool_name, tool_args,
)
else:
return get_approval_registry().approve_sync(
getattr(self, 'name', None), tool_name, tool_args,
)
def _check_tool_approval_sync(self, function_name, arguments):
"""Check tool approval synchronously. Returns (decision, arguments) or error dict."""
# Permission tier fast-path (O(1) frozenset lookup, resolved at __init__)
if self._perm_deny and function_name in self._perm_deny:
return {"error": f"Tool '{function_name}' blocked by permission policy", "permission_denied": True}
if self._perm_allow is not None and function_name not in self._perm_allow:
return {"error": f"Tool '{function_name}' not in allowed tools list", "permission_denied": True}
decision = self._resolve_approval_decision(function_name, arguments, is_async=False)
if not decision.approved:
error_msg = f"Tool execution denied: {decision.reason}"
logging.warning(error_msg)
return {"error": error_msg, "approval_denied": True}
from ..approval import get_approval_registry
get_approval_registry().mark_approved(function_name)
if decision.modified_args:
arguments = decision.modified_args
logging.info(f"Using modified arguments: {arguments}")
return None, arguments
async def _check_tool_approval_async(self, function_name, arguments):
"""Check tool approval asynchronously. Returns (decision, arguments) or error dict."""
# Permission tier fast-path (O(1) frozenset lookup, resolved at __init__)
if self._perm_deny and function_name in self._perm_deny:
return {"error": f"Tool '{function_name}' blocked by permission policy", "permission_denied": True}
if self._perm_allow is not None and function_name not in self._perm_allow:
return {"error": f"Tool '{function_name}' not in allowed tools list", "permission_denied": True}
decision_coro = self._resolve_approval_decision(function_name, arguments, is_async=True)
decision = await decision_coro
if not decision.approved:
error_msg = f"Tool execution denied: {decision.reason}"
logging.warning(error_msg)
return {"error": error_msg, "approval_denied": True}
from ..approval import get_approval_registry
get_approval_registry().mark_approved(function_name)
if decision.modified_args:
arguments = decision.modified_args
logging.info(f"Using modified arguments: {arguments}")
return None, arguments
def _execute_tool_impl(self, function_name, arguments):
"""Internal tool execution implementation."""
# Check if approval is required for this tool (protocol-driven)
try:
result = self._check_tool_approval_sync(function_name, arguments)
if isinstance(result, dict):
return result # Error dict
_, arguments = result
except Exception as e:
error_msg = f"Error during approval process: {str(e)}"
logging.error(error_msg)
return {"error": error_msg, "approval_error": True}
# Special handling for MCP tools
# Check if tools is an MCP instance with the requested function name
MCP = None
try:
from ..mcp.mcp import MCP
except ImportError:
pass # MCP not available
# Helper function to execute MCP tool
def _execute_mcp_tool(mcp_instance, func_name, args):
"""Execute a tool from an MCP instance."""
# Handle SSE MCP client
if hasattr(mcp_instance, 'is_sse') and mcp_instance.is_sse:
if hasattr(mcp_instance, 'sse_client'):
for tool in mcp_instance.sse_client.tools:
if tool.name == func_name:
logging.debug(f"Found matching SSE MCP tool: {func_name}")
return True, tool(**args)
# Handle HTTP Stream MCP client
if hasattr(mcp_instance, 'is_http_stream') and mcp_instance.is_http_stream:
if hasattr(mcp_instance, 'http_stream_client'):
for tool in mcp_instance.http_stream_client.tools:
if tool.name == func_name:
logging.debug(f"Found matching HTTP Stream MCP tool: {func_name}")
return True, tool(**args)
# Handle WebSocket MCP client
if hasattr(mcp_instance, 'is_websocket') and mcp_instance.is_websocket:
if hasattr(mcp_instance, 'websocket_client'):
for tool in mcp_instance.websocket_client.tools:
if tool.name == func_name:
logging.debug(f"Found matching WebSocket MCP tool: {func_name}")
return True, tool(**args)
# Handle stdio MCP client
if hasattr(mcp_instance, 'runner'):
for mcp_tool in mcp_instance.runner.tools:
if hasattr(mcp_tool, 'name') and mcp_tool.name == func_name:
logging.debug(f"Found matching MCP tool: {func_name}")
return True, mcp_instance.runner.call_tool(func_name, args)
return False, None
# Check if tools is a single MCP instance
if MCP is not None and isinstance(self.tools, MCP):
logging.debug(f"Looking for MCP tool {function_name}")
found, result = _execute_mcp_tool(self.tools, function_name, arguments)
if found:
return result
# Check if tools is a list that may contain MCP instances
if isinstance(self.tools, (list, tuple)):
for tool in self.tools:
if MCP is not None and isinstance(tool, MCP):
logging.debug(f"Looking for MCP tool {function_name} in MCP instance")
found, result = _execute_mcp_tool(tool, function_name, arguments)
if found:
return result
# Try to find the function in the agent's tools list first
func = None
for tool in self.tools if isinstance(self.tools, (list, tuple)) else []:
# Check for BaseTool instances (plugin system)
from ..tools.base import BaseTool
if isinstance(tool, BaseTool) and tool.name == function_name:
func = tool
break
# Check for FunctionTool (decorated functions)
if hasattr(tool, 'name') and getattr(tool, 'name', None) == function_name:
func = tool
break
if (callable(tool) and getattr(tool, '__name__', '') == function_name) or \
(inspect.isclass(tool) and tool.__name__ == function_name):
func = tool
break
if func is None:
# Check the global tool registry for plugins
try:
from ..tools.registry import get_registry
registry = get_registry()
func = registry.get(function_name)
except ImportError:
pass
if func is None:
# If not found in tools or registry, try globals and main
func = globals().get(function_name)
if not func:
import __main__
func = getattr(__main__, function_name, None)
if func:
try:
# BaseTool instances (plugin system) - call run() method
from ..tools.base import BaseTool
if isinstance(func, BaseTool):
casted_arguments = self._cast_arguments(func.run, arguments)
return func.run(**casted_arguments)
# Langchain: If it's a class with run but not _run, instantiate and call run
if inspect.isclass(func) and hasattr(func, 'run') and not hasattr(func, '_run'):
instance = func()
run_params = {k: v for k, v in arguments.items()
if k in inspect.signature(instance.run).parameters
and k != 'self'}
casted_params = self._cast_arguments(instance.run, run_params)
return instance.run(**casted_params)
# CrewAI: If it's a class with an _run method, instantiate and call _run
elif inspect.isclass(func) and hasattr(func, '_run'):
instance = func()
run_params = {k: v for k, v in arguments.items()
if k in inspect.signature(instance._run).parameters
and k != 'self'}
casted_params = self._cast_arguments(instance._run, run_params)
return instance._run(**casted_params)
# Otherwise treat as regular function
elif callable(func):
casted_arguments = self._cast_arguments(func, arguments)
return func(**casted_arguments)
except Exception as e:
error_msg = str(e)
logging.error(f"Error executing tool {function_name}: {error_msg}")
return {"error": error_msg}
error_msg = f"Tool '{function_name}' is not callable"
logging.error(error_msg)
return {"error": error_msg}
async def submit_for_approval(self, function_name: str, arguments: Dict[str, Any]) -> str:
"""Fire an approval request in the background without blocking.
Returns a tracking ID. The agent can continue other work while the
approval is pending. Call :meth:`check_pending_approvals` to poll
for results and auto-execute approved tools.
"""
import uuid
backend = getattr(self, '_approval_backend', None)
if backend is None:
raise RuntimeError("No approval backend configured on this agent")
from ..approval.protocols import ApprovalRequest
from ..approval.registry import DEFAULT_DANGEROUS_TOOLS
request = ApprovalRequest(
tool_name=function_name,
arguments=arguments,
risk_level=DEFAULT_DANGEROUS_TOOLS.get(function_name, "medium"),
agent_name=getattr(self, 'name', None),
)
tracking_id = str(uuid.uuid4())[:8]
task = asyncio.ensure_future(backend.request_approval(request))
self._pending_approvals[tracking_id] = {
"task": task,
"function_name": function_name,
"arguments": arguments,
"request": request,
}
logging.info(f"Approval request submitted: {tracking_id} for {function_name}")
return tracking_id
async def check_pending_approvals(self) -> Dict[str, Any]:
"""Check and process any completed approval requests.
Returns a dict of ``{tracking_id: result}`` for approvals that
completed since the last check. Approved tools are auto-executed
and their results included.
"""
results = {}
completed_ids = []
for tid, info in self._pending_approvals.items():
task = info["task"]
if task.done():
completed_ids.append(tid)
try:
decision = task.result()
if decision.approved:
# Auto-execute the approved tool
tool_result = await self.execute_tool_async(
info["function_name"], info["arguments"],
)
results[tid] = {
"status": "approved_and_executed",
"tool_name": info["function_name"],
"decision": decision,
"result": tool_result,
}
else:
results[tid] = {
"status": "denied",
"tool_name": info["function_name"],
"decision": decision,
}
except Exception as e:
results[tid] = {
"status": "error",
"tool_name": info["function_name"],
"error": str(e),
}
for tid in completed_ids:
del self._pending_approvals[tid]
return results
def pending_approval_count(self) -> int:
"""Number of approval requests still waiting."""
return len(self._pending_approvals)
@@ -12,6 +12,7 @@ Follows the Agent() class patterns:
import os
import time
import logging
from praisonaiagents._logging import get_logger
import asyncio
import warnings
from dataclasses import dataclass, field
@@ -20,7 +21,6 @@ from typing import Optional, Any, Dict, Union, List, Generator
# Filter out Pydantic warning about fields
warnings.filterwarnings("ignore", "Valid config keys have changed in V2", UserWarning)
# ─────────────────────────────────────────────────────────────────────────────
# VideoConfig - Configuration dataclass following feature_configs.py patterns
# ─────────────────────────────────────────────────────────────────────────────
@@ -79,7 +79,6 @@ class VideoConfig:
"api_version": self.api_version,
}
# ─────────────────────────────────────────────────────────────────────────────
# VideoAgent Class - Agent-centric video generation
# ─────────────────────────────────────────────────────────────────────────────
@@ -265,12 +264,12 @@ class VideoAgent:
"""Configure logging levels based on verbose setting."""
if isinstance(verbose, int) and verbose >= 10:
# Debug mode
logging.getLogger("litellm").setLevel(logging.DEBUG)
get_logger("litellm").setLevel(logging.DEBUG)
else:
# Suppress debug logging
logging.getLogger("litellm").setLevel(logging.WARNING)
logging.getLogger("httpx").setLevel(logging.WARNING)
logging.getLogger("httpcore").setLevel(logging.WARNING)
get_logger("litellm").setLevel(logging.WARNING)
get_logger("httpx").setLevel(logging.WARNING)
get_logger("httpcore").setLevel(logging.WARNING)
def _get_model_params(self) -> Dict[str, Any]:
"""Build parameters for LiteLLM video calls."""
@@ -12,12 +12,12 @@ Follows the Agent() class patterns with:
import os
import logging
from praisonaiagents._logging import get_logger
from dataclasses import dataclass
from typing import Optional, Dict, Any, Union, List
from pathlib import Path
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
@dataclass
class VisionConfig:
@@ -44,7 +44,6 @@ class VisionConfig:
"api_key": self.api_key,
}
class VisionAgent:
"""
A specialized agent for image analysis and understanding.
@@ -166,10 +165,10 @@ class VisionAgent:
def _configure_logging(self, verbose: Union[bool, int]) -> None:
"""Configure logging levels."""
if isinstance(verbose, int) and verbose >= 10:
logging.getLogger("litellm").setLevel(logging.DEBUG)
get_logger("litellm").setLevel(logging.DEBUG)
else:
logging.getLogger("litellm").setLevel(logging.WARNING)
logging.getLogger("httpx").setLevel(logging.WARNING)
get_logger("litellm").setLevel(logging.WARNING)
get_logger("httpx").setLevel(logging.WARNING)
def _get_model_params(self, model: Optional[str] = None) -> Dict[str, Any]:
"""Build parameters for LiteLLM calls."""
@@ -2,6 +2,7 @@ import os
import time
import json
import logging
from praisonaiagents._logging import get_logger
from typing import Any, Dict, Optional, List
from ..main import display_error, TaskOutput
from ..agent.agent import Agent
@@ -27,7 +28,7 @@ class TaskStatus(Enum):
UNKNOWN = "unknown"
# Set up logger
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
# Global variables for managing the shared servers with thread-safety
import threading
@@ -63,7 +64,6 @@ def process_video(video_path: str, seconds_per_frame=2):
video.release()
return base64_frames
def get_multimodal_message(text_prompt: str, images: list) -> list:
"""
Build multimodal message content for LLM with text and images.
@@ -108,7 +108,6 @@ def get_multimodal_message(text_prompt: str, images: list) -> list:
})
return content
def process_task_context(context_item, verbose=0, user_id=None):
"""
Process a single context item for task execution.
@@ -450,17 +449,18 @@ class AgentTeam:
# Set logger level based on verbose
if _verbose >= 5:
logger.setLevel(logging.INFO)
logger.setLevel(10) # DEBUG
elif _verbose >= 3:
logger.setLevel(logging.DEBUG)
logger.setLevel(20) # INFO
else:
logger.setLevel(logging.WARNING)
logger.setLevel(30) # WARNING
# Also set third-party loggers to WARNING
logging.getLogger('chromadb').setLevel(logging.WARNING)
logging.getLogger('openai').setLevel(logging.WARNING)
logging.getLogger('httpx').setLevel(logging.WARNING)
logging.getLogger('httpcore').setLevel(logging.WARNING)
import logging as _logging
get_logger('chromadb').setLevel(_logging.WARNING)
get_logger('openai').setLevel(_logging.WARNING)
get_logger('httpx').setLevel(_logging.WARNING)
get_logger('httpcore').setLevel(_logging.WARNING)
if self.verbose:
logger.info(f"Using model {self.manager_llm} for manager")
@@ -653,28 +653,46 @@ class AgentTeam:
if task.status == "not started":
task.status = "in progress"
# Initialize memory before task execution
if not task.memory:
task.memory = task.initialize_memory()
executor_agent = task.agent
# Create agent from agent_config if provided and no agent assigned
if executor_agent is None and getattr(task, 'agent_config', None):
executor_agent = self._create_agent_from_config(task.agent_config)
task.agent = executor_agent
# Set current agent for token tracking
llm = getattr(executor_agent, 'llm', None) or getattr(executor_agent, 'llm_instance', None)
if llm and hasattr(llm, 'set_current_agent'):
llm.set_current_agent(executor_agent.display_name)
# Ensure tools are available from both task and agent
tools = task.tools or []
# Ensure tools are available from both task and agent (create copy to avoid mutation)
tools = list(task.tools or [])
if executor_agent and executor_agent.tools:
tools.extend(executor_agent.tools)
task_prompt = f"""
You need to do the following task: {task.description}.
Expected Output: {task.expected_output}.
"""
logger.info(f"Task config: {task.config}")
logger.info(f"Task memory status: {'Initialized' if task.memory else 'Not initialized'}")
# Substitute variables in task description if provided
task_description = task.description
if getattr(task, 'variables', None):
for key, value in task.variables.items():
task_description = task_description.replace(f"{{{{{key}}}}}", str(value))
# Build context first to include in task prompt
context_text = ""
if task.context:
context_results = [] # Use list to avoid duplicates
for context_item in task.context:
# Use the centralized helper function
context_str = process_task_context(context_item, self.verbose, self.user_id)
context_results.append(context_str)
# Only add non-empty context strings
if context_str and context_str.strip():
context_results.append(context_str)
# Join unique context results with proper formatting
unique_contexts = list(dict.fromkeys(context_results)) # Remove duplicates
@@ -683,15 +701,38 @@ Expected Output: {task.expected_output}.
for i, ctx in enumerate(unique_contexts):
logger.debug(f"Context {i+1}: {ctx[:100]}...")
context_separator = '\n\n'
task_prompt += f"""
Context:
context_text = context_separator.join(unique_contexts)
# Build task prompt - only use "User Input/Topic" format if there's actual content
if context_text and context_text.strip():
task_prompt = f"""
User Input/Topic: {context_text}
{context_separator.join(unique_contexts)}
"""
task_prompt += "Please provide only the final result of your work. Do not add any conversation or extra explanation."
Task: {task_description}
Expected Output: {task.expected_output}
IMPORTANT: Your response must be about the user's input/topic above. Incorporate it into your task."""
else:
task_prompt = f"""
You need to do the following task: {task_description}.
Expected Output: {task.expected_output}."""
# Add memory context if available
if task.memory:
try:
memory_context = task.memory.build_context_for_task(task.description)
if memory_context:
# Log detailed memory context for debugging
logger.debug(f"Memory context for task '{task.description}': {memory_context}")
# Include actual memory content without verbose headers (essential for AI agent functionality)
task_prompt += f"\n\n{memory_context}"
except Exception as e:
logger.error(f"Error getting memory context: {e}")
task_prompt += "\nPlease provide only the final result of your work. Do not add any conversation or extra explanation."
if self.verbose >= 2:
logger.info(f"Executing task {task_id}: {task.description} using {executor_agent.display_name}")
logger.info(f"Executing task {task_id}: {task_description} using {executor_agent.display_name}")
logger.debug(f"Starting execution of task {task_id} with prompt:\n{task_prompt}")
if task.images:
@@ -717,6 +758,17 @@ Context:
)
if agent_output:
# Store the response in memory
if task.memory:
try:
task.store_in_memory(
content=agent_output,
agent_name=executor_agent.display_name,
task_id=task_id
)
except Exception as e:
logger.error(f"Failed to store agent output in memory: {e}")
task_output = TaskOutput(
description=task.description,
summary=task.description[:10],
@@ -983,22 +1035,27 @@ Context:
if llm and hasattr(llm, 'set_current_agent'):
llm.set_current_agent(executor_agent.display_name)
# Ensure tools are available from both task and agent (create copy to avoid mutation)
tools = list(task.tools or [])
if executor_agent and executor_agent.tools:
tools.extend(executor_agent.tools)
# Substitute variables in task description if provided
task_description = task.description
if getattr(task, 'variables', None):
for key, value in task.variables.items():
task_description = task_description.replace(f"{{{{{key}}}}}", str(value))
task_prompt = f"""
You need to do the following task: {task_description}.
Expected Output: {task.expected_output}.
"""
# Build context first to include in task prompt
context_text = ""
if task.context:
context_results = [] # Use list to avoid duplicates
for context_item in task.context:
# Use the centralized helper function
context_str = process_task_context(context_item, self.verbose, self.user_id)
context_results.append(context_str)
# Only add non-empty context strings
if context_str and context_str.strip():
context_results.append(context_str)
# Join unique context results with proper formatting
unique_contexts = list(dict.fromkeys(context_results)) # Remove duplicates
@@ -1007,11 +1064,21 @@ Expected Output: {task.expected_output}.
for i, ctx in enumerate(unique_contexts):
logger.debug(f"Context {i+1}: {ctx[:100]}...")
context_separator = '\n\n'
task_prompt += f"""
Context:
context_text = context_separator.join(unique_contexts)
# Build task prompt - only use "User Input/Topic" format if there's actual content
if context_text and context_text.strip():
task_prompt = f"""
User Input/Topic: {context_text}
{context_separator.join(unique_contexts)}
"""
Task: {task_description}
Expected Output: {task.expected_output}
IMPORTANT: Your response must be about the user's input/topic above. Incorporate it into your task."""
else:
task_prompt = f"""
You need to do the following task: {task_description}.
Expected Output: {task.expected_output}."""
# Add memory context if available
if task.memory:
@@ -1025,7 +1092,7 @@ Context:
except Exception as e:
logger.error(f"Error getting memory context: {e}")
task_prompt += "Please provide only the final result of your work. Do not add any conversation or extra explanation."
task_prompt += "\nPlease provide only the final result of your work. Do not add any conversation or extra explanation."
if self.verbose >= 2:
logger.info(f"Executing task {task_id}: {task.description} using {executor_agent.display_name}")
@@ -1035,7 +1102,7 @@ Context:
# Use shared multimodal helper (DRY - defined at module level)
agent_output = executor_agent.chat(
get_multimodal_message(task_prompt, task.images),
tools=task.tools,
tools=tools,
output_json=task.output_json,
output_pydantic=task.output_pydantic,
task_name=task.name,
@@ -1045,7 +1112,7 @@ Context:
else:
agent_output = executor_agent.chat(
task_prompt,
tools=task.tools,
tools=tools,
output_json=task.output_json,
output_pydantic=task.output_pydantic,
stream=self.stream,
@@ -2435,7 +2502,6 @@ Context:
self._plan_tasks = self.tasks.copy()
# Keep plan tasks for results but note original tasks are preserved in _plan_tasks
# Backward compatibility aliases (silent - no deprecation warnings)
# AgentTeam is the primary name (v1.0+)
# AgentManager, Agents, PraisonAIAgents are silent aliases
@@ -18,6 +18,7 @@ Usage:
"""
import logging
from praisonaiagents._logging import get_logger
import time
from dataclasses import dataclass, field
from enum import Enum
@@ -27,8 +28,7 @@ if TYPE_CHECKING:
from praisonaiagents.agent import Agent
from praisonaiagents.rag import RAG, ContextPack
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
class RetrievalPolicy(Enum):
"""Policy for when to perform RAG retrieval."""
@@ -36,7 +36,6 @@ class RetrievalPolicy(Enum):
ALWAYS = "always" # Always retrieve
NEVER = "never" # Never retrieve (direct chat only)
@dataclass
class AutoRagConfig:
"""Configuration for AutoRagAgent."""
@@ -101,7 +100,6 @@ class AutoRagConfig:
return cls(**kwargs)
class AutoRagAgent:
"""
Agent wrapper with automatic RAG retrieval decision.
@@ -10,6 +10,7 @@ from ..agent.agent import Agent
from ..task.task import Task
from typing import List, Any, Optional, Dict, Tuple
import logging
from praisonaiagents._logging import get_logger
import os
from pydantic import BaseModel, ConfigDict
from ..main import display_instruction, display_tool_call, display_interaction
@@ -360,7 +361,7 @@ DO NOT use strings for tasks. Each task MUST be a complete object with all four
use_openai_structured = True
except Exception as e:
# If OpenAI client is not available, we'll use the LLM class
logging.getLogger(__name__).debug(f"OpenAI client not available, falling back to LLM class: {e}")
get_logger(__name__).debug(f"OpenAI client not available, falling back to LLM class: {e}")
try:
if use_openai_structured and client:
@@ -6,6 +6,7 @@ and context. Inspired by Gemini CLI's delegate-to-agent pattern.
"""
import logging
from praisonaiagents._logging import get_logger
import asyncio
from dataclasses import dataclass, field
from typing import Any, Dict, List, Optional, Callable
@@ -13,8 +14,7 @@ from enum import Enum
from .profiles import AgentProfile, AgentMode, get_profile, BUILTIN_PROFILES
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
class DelegationStatus(Enum):
"""Status of a delegated task."""
@@ -25,7 +25,6 @@ class DelegationStatus(Enum):
CANCELLED = "cancelled"
TIMEOUT = "timeout"
@dataclass
class DelegationConfig:
"""Configuration for subagent delegation."""
@@ -49,7 +48,6 @@ class DelegationConfig:
auto_cancel_on_parent_cancel: bool = True
collect_results: bool = True
@dataclass
class DelegationTask:
"""A task delegated to a subagent."""
@@ -75,7 +73,6 @@ class DelegationTask:
# Metadata
metadata: Dict[str, Any] = field(default_factory=dict)
@dataclass
class DelegationResult:
"""Result of a delegation operation."""
@@ -88,7 +85,6 @@ class DelegationResult:
tokens_used: int = 0
duration_seconds: float = 0.0
class SubagentDelegator:
"""
Manages delegation of tasks to subagents.
@@ -448,7 +444,6 @@ class SubagentDelegator:
self._task_counter += 1
return f"task_{self._task_counter}"
# Convenience function for quick delegation
async def delegate_to_agent(
agent_name: str,
@@ -33,6 +33,7 @@ import asyncio
import contextvars
import json
import logging
from praisonaiagents._logging import get_logger
import os
from dataclasses import dataclass, field
from functools import wraps
@@ -45,13 +46,12 @@ from .protocols import ApprovalDecision # noqa: F401
from .backends import AutoApproveBackend, ConsoleBackend, CallbackBackend, AgentApproval # noqa: F401
from .registry import ApprovalRegistry, DEFAULT_DANGEROUS_TOOLS # noqa: F401
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
# ── Singleton registry ───────────────────────────────────────────────────────
_registry: Optional[ApprovalRegistry] = None
def get_approval_registry() -> ApprovalRegistry:
"""Return the global singleton :class:`ApprovalRegistry`."""
global _registry
@@ -59,7 +59,6 @@ def get_approval_registry() -> ApprovalRegistry:
_registry = ApprovalRegistry()
return _registry
# ── Backward-compatible API (delegates to registry) ─────────────────────────
# These globals are kept for code that imports them directly.
@@ -69,7 +68,6 @@ TOOL_RISK_LEVELS: Dict[str, str] = get_approval_registry()._risk_levels
# Legacy global callback holder — set_approval_callback wraps it into a backend
approval_callback: Optional[Callable] = None
def set_approval_callback(callback_fn: Optional[Callable]) -> None:
"""Set a custom approval callback (legacy API).
@@ -84,67 +82,53 @@ def set_approval_callback(callback_fn: Optional[Callable]) -> None:
else:
reg.remove_backend()
def get_approval_callback() -> Optional[Callable]:
"""Get the current approval callback function (legacy API)."""
return approval_callback
def mark_approved(tool_name: str) -> None:
get_approval_registry().mark_approved(tool_name)
def is_already_approved(tool_name: str) -> bool:
return get_approval_registry().is_already_approved(tool_name)
def is_yaml_approved(tool_name: str) -> bool:
return get_approval_registry().is_yaml_approved(tool_name)
def is_env_auto_approve() -> bool:
return ApprovalRegistry.is_env_auto_approve()
def set_yaml_approved_tools(tools: List[str]) -> contextvars.Token:
return get_approval_registry().set_yaml_approved_tools(tools)
def reset_yaml_approved_tools(token: contextvars.Token) -> None:
get_approval_registry().reset_yaml_approved_tools(token)
def clear_approval_context() -> None:
get_approval_registry().clear_approved()
def configure_default_approvals() -> None:
"""Re-configure default dangerous tools (idempotent)."""
reg = get_approval_registry()
for tool_name, risk_level in DEFAULT_DANGEROUS_TOOLS.items():
reg.add_requirement(tool_name, risk_level)
def add_approval_requirement(tool_name: str, risk_level: str = "high") -> None:
get_approval_registry().add_requirement(tool_name, risk_level)
APPROVAL_REQUIRED_TOOLS.add(tool_name)
TOOL_RISK_LEVELS[tool_name] = risk_level
def remove_approval_requirement(tool_name: str) -> None:
get_approval_registry().remove_requirement(tool_name)
APPROVAL_REQUIRED_TOOLS.discard(tool_name)
TOOL_RISK_LEVELS.pop(tool_name, None)
def is_approval_required(tool_name: str) -> bool:
return get_approval_registry().is_required(tool_name)
def get_risk_level(tool_name: str) -> Optional[str]:
return get_approval_registry().get_risk_level(tool_name)
# ── Legacy console callback (kept for direct callers) ───────────────────────
def console_approval_callback(function_name: str, arguments: Dict, risk_level: str) -> ApprovalDecision:
@@ -157,19 +141,16 @@ def console_approval_callback(function_name: str, arguments: Dict, risk_level: s
)
return backend.request_approval_sync(request)
# ── Legacy async request_approval ────────────────────────────────────────────
async def request_approval(function_name: str, arguments: Dict) -> ApprovalDecision:
"""Request approval for a tool execution (legacy async API)."""
return await get_approval_registry().approve_async(None, function_name, arguments)
# ── require_approval decorator (unchanged semantics) ─────────────────────────
RiskLevel = Literal["critical", "high", "medium", "low"]
def require_approval(risk_level: RiskLevel = "high"):
"""Decorator to mark a tool as requiring human approval."""
def decorator(func):
@@ -228,10 +209,8 @@ def require_approval(risk_level: RiskLevel = "high"):
return decorator
# ── PermissionAllowlist (kept as-is) ─────────────────────────────────────────
@dataclass
class ToolPermission:
"""Permission entry for a tool."""
@@ -239,7 +218,6 @@ class ToolPermission:
allowed_paths: List[str] = field(default_factory=list)
session_only: bool = False
class PermissionAllowlist:
"""Persistent permission allowlist for tools."""
@@ -309,17 +287,14 @@ class PermissionAllowlist:
allowlist.add_tool(tool_name, paths=tool_data.get("allowed_paths", []), session_only=tool_data.get("session_only", False))
return allowlist
_permission_allowlist: Optional[PermissionAllowlist] = None
def get_permission_allowlist() -> PermissionAllowlist:
global _permission_allowlist
if _permission_allowlist is None:
_permission_allowlist = PermissionAllowlist()
return _permission_allowlist
def set_permission_allowlist(allowlist: PermissionAllowlist) -> None:
global _permission_allowlist
_permission_allowlist = allowlist
@@ -12,18 +12,18 @@ from __future__ import annotations
import asyncio
import logging
from praisonaiagents._logging import get_logger
from typing import Any
from .protocols import ApprovalDecision, ApprovalRequest
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
# Lazy Rich imports (same pattern as old approval.py)
_rich_console = None
_rich_panel = None
_rich_confirm = None
def _get_rich_console():
global _rich_console
if _rich_console is None:
@@ -31,7 +31,6 @@ def _get_rich_console():
_rich_console = Console
return _rich_console
def _get_rich_panel():
global _rich_panel
if _rich_panel is None:
@@ -39,7 +38,6 @@ def _get_rich_panel():
_rich_panel = Panel
return _rich_panel
def _get_rich_confirm():
global _rich_confirm
if _rich_confirm is None:
@@ -47,7 +45,6 @@ def _get_rich_confirm():
_rich_confirm = Confirm
return _rich_confirm
class AutoApproveBackend:
"""Always approves. Use for bots or trusted unattended environments."""
@@ -57,7 +54,6 @@ class AutoApproveBackend:
def request_approval_sync(self, request: ApprovalRequest) -> ApprovalDecision:
return ApprovalDecision(approved=True, reason="auto-approved", approver="system")
class ConsoleBackend:
"""Interactive Rich terminal prompt. Default for CLI usage."""
@@ -119,7 +115,6 @@ class ConsoleBackend:
loop = asyncio.get_running_loop()
return await loop.run_in_executor(None, self.request_approval_sync, request)
class AgentApproval:
"""Delegates approval decisions to another AI agent.
@@ -240,7 +235,6 @@ class AgentApproval:
from .utils import run_coroutine_safely
return run_coroutine_safely(self.request_approval(request), timeout=60)
class CallbackBackend:
"""Wraps a legacy ``(function_name, arguments, risk_level) -> ApprovalDecision`` callback
into an :class:`ApprovalProtocol`-compatible backend.
@@ -19,12 +19,13 @@ from __future__ import annotations
import asyncio
import contextvars
import logging
from praisonaiagents._logging import get_logger
import os
from typing import Dict, List, Optional, Set
from .protocols import ApprovalDecision, ApprovalRequest
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
# Default dangerous tools — same as old approval.py
DEFAULT_DANGEROUS_TOOLS: Dict[str, str] = {
@@ -58,7 +59,6 @@ PERMISSION_PRESETS = {
"full": frozenset(),
}
class ApprovalRegistry:
"""Per-agent approval configuration.
@@ -6,14 +6,14 @@ Manages background task execution.
import asyncio
import logging
from praisonaiagents._logging import get_logger
from typing import Optional, List, Dict, Any, Callable, Union
from datetime import datetime
from .task import BackgroundTask, TaskStatus
from .config import BackgroundConfig
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
class BackgroundRunner:
"""
@@ -392,7 +392,6 @@ class BackgroundRunner:
)
return future.result(timeout=5)
# ── Module-level background event loop (lazy, daemon) ───────────────────
import threading as _threading
@@ -400,7 +399,6 @@ import threading as _threading
_bg_loop: Optional[asyncio.AbstractEventLoop] = None
_bg_lock = _threading.Lock()
def _get_bg_loop() -> asyncio.AbstractEventLoop:
"""Return a running event loop on a background daemon thread.
@@ -7,13 +7,13 @@ Represents a task running in the background.
import uuid
import asyncio
import logging
from praisonaiagents._logging import get_logger
from enum import Enum
from dataclasses import dataclass, field
from typing import Optional, Any, Callable, Dict
from datetime import datetime
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
class TaskStatus(str, Enum):
"""Status of a background task."""
@@ -23,7 +23,6 @@ class TaskStatus(str, Enum):
FAILED = "failed"
CANCELLED = "cancelled"
@dataclass
class BackgroundTask:
"""
@@ -6,13 +6,13 @@ Provides publish/subscribe functionality for typed events.
import asyncio
import logging
from praisonaiagents._logging import get_logger
import threading
from typing import Any, Callable, Dict, List, Optional, Set, Union
from dataclasses import dataclass, field
from .event import Event, EventType
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
@dataclass
class Subscriber:
@@ -36,7 +36,6 @@ class Subscriber:
return True
return event_type in self.event_types
class EventBus:
"""
Event bus for publish/subscribe communication.
@@ -324,12 +323,10 @@ class EventBus:
def __repr__(self) -> str:
return f"EventBus(subscribers={self.subscriber_count})"
# Global default bus
_default_bus: Optional[EventBus] = None
_bus_lock = threading.Lock()
def get_default_bus() -> EventBus:
"""Get the default global event bus."""
global _default_bus
@@ -338,7 +335,6 @@ def get_default_bus() -> EventBus:
_default_bus = EventBus()
return _default_bus
def set_default_bus(bus: EventBus):
"""Set the default global event bus."""
global _default_bus
@@ -7,6 +7,7 @@ Implements shadow git repository for file-level checkpointing.
import os
import asyncio
import logging
from praisonaiagents._logging import get_logger
import shutil
from typing import Optional, List, Dict, Any, Callable
from datetime import datetime
@@ -17,8 +18,7 @@ from .types import (
CheckpointResult, CheckpointEvent
)
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
def _parse_iso_timestamp(timestamp: str) -> datetime:
"""Parse ISO format timestamp, handling 'Z' suffix for Python 3.9 compatibility."""
@@ -39,7 +39,6 @@ PROTECTED_PATHS = [
"/etc",
]
class CheckpointService:
"""
Shadow Git Checkpoint Service.
@@ -9,10 +9,10 @@ to enable DRY condition handling across the codebase.
"""
import re
import logging
from praisonaiagents._logging import get_logger
from typing import Dict, Any, List, Optional
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
class ExpressionCondition:
"""
@@ -62,7 +62,6 @@ class ExpressionCondition:
def __repr__(self) -> str:
return f"ExpressionCondition({self.expression!r})"
class DictCondition:
"""
Dict-based condition evaluator for routing decisions.
@@ -127,7 +126,6 @@ class DictCondition:
def __repr__(self) -> str:
return f"DictCondition(routes={self.routes!r}, key={self.key!r})"
def evaluate_condition(
condition: str,
variables: Dict[str, Any],
@@ -30,6 +30,7 @@ import os
from pathlib import Path
from typing import Any, Dict, List, Optional, Union
from dataclasses import dataclass, field
from functools import lru_cache
# ============================================================================
@@ -331,6 +332,7 @@ def get_plugins_config() -> PluginsConfig:
return get_config().plugins
@lru_cache(maxsize=1)
def get_defaults_config() -> DefaultsConfig:
"""Get defaults configuration.
@@ -7,11 +7,11 @@ Inspired by CrewAI's ContextualMemory pattern.
import asyncio
import logging
from praisonaiagents._logging import get_logger
from dataclasses import dataclass, field
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
logger = logging.getLogger(__name__)
logger = get_logger(__name__)
@dataclass
class AggregatedContext:
@@ -30,7 +30,6 @@ class AggregatedContext:
"fetch_times": self.fetch_times,
}
class ContextAggregator:
"""
Aggregates context from multiple memory sources concurrently.
@@ -288,7 +287,6 @@ class ContextAggregator:
# Fallback - create new event loop
return asyncio.run(self.aggregate(query, sources, max_tokens))
def create_aggregator_from_config(
memory = None,
knowledge = None,
Loaded 100 of 329 files, more files were not shown because too many files have changed in this diff. Show more