Compare commits

...
Author SHA1 Message Date
praisonai-triage-agent[bot]andMervin Praison ce8fe5f88d fix: carry Windows lock length through load() and correct conftest agents path
- load() now passes the acquired lock_length to _release_exclusive_lock so
  Windows unlocks the exact byte range it locked (max(file_size,1)), fixing a
  release/lock mismatch on nonempty session files.
- conftest _agents_path now resolves to src/praisonai-agents (was pointing to a
  nonexistent repo-root praisonai-agents), fixing test collection on source
  checkouts. Corrected path comments.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-29 10:06:56 +00:00
Hore01 2e4d0c571c fix: preserve Windows file lock length during save 2026-07-29 10:58:37 +01:00
MervinPraison e3e0135876 docs: auto-update documentation parity trackers [skip ci] 2026-07-28 18:54:32 +00:00
praisonai-triage-agent[bot] ed4c63f141 Merge pull request #3488 from MervinPraison/claude/issue-3485-20260728-1714
fix: remove orphaned hooks/query_protocol.py dead code
2026-07-28 18:53:38 +00:00
MervinPraison 6b91970049 Release v4.6.157 2026-07-28 18:50:30 +00:00
MervinPraison a8ec2f15a3 Bump praisonai-sandbox to 0.0.7 2026-07-28 18:50:24 +00:00
MervinPraison 52d5320699 Bump praisonai-mcp to 0.0.9 2026-07-28 18:50:19 +00:00
MervinPraison fcab98a2aa Bump praisonai-browser to 0.0.9 2026-07-28 18:50:12 +00:00
MervinPraison 2055ecf05d Bump praisonai-train to 0.0.13 2026-07-28 18:50:05 +00:00
MervinPraison 20bc67ae82 Bump praisonai-bot to 0.0.42 2026-07-28 18:49:59 +00:00
MervinPraison b1a3cda2a9 Bump praisonai-code to 0.0.57 2026-07-28 18:49:51 +00:00
MervinPraison 878c212f18 Bump praisonaiagents to 1.6.161 2026-07-28 18:49:14 +00:00
praisonai-triage-agent[bot] 0e5fd5416d Merge pull request #3487 from MervinPraison/claude/issue-3484-20260728-1714
fix: remove dead deprecated _classify_error_and_should_retry_legacy
2026-07-28 18:38:15 +00:00
MervinPraison f079b0266a docs: auto-update documentation parity trackers [skip ci] 2026-07-28 18:31:27 +00:00
praisonai-triage-agent[bot] dac4248669 Merge pull request #3486 from MervinPraison/claude/issue-3482-20260728-1713
fix: restore retry tuning and compaction_strategy in ExecutionConfig.from_dict
2026-07-28 18:30:44 +00:00
Hore01 37cea31ea9 fix: resolve pytest_plugins error with pytest 9 2026-07-28 18:32:08 +01:00
praisonai-triage-agent[bot]andMervinPraison 19d410aa2d fix: remove orphaned hooks/query_protocol.py dead code (fixes #3485)
HooksQueryProtocol had zero importers, was not exported in
hooks/__init__.py __all__ or _LAZY_GROUPS. Consumers use
registry.list_hooks_for_api directly. No behaviour change.

Co-authored-by: MervinPraison <[email protected]>
2026-07-28 17:16:05 +00:00
praisonai-triage-agent[bot]andMervinPraison c954072257 fix: remove dead deprecated _classify_error_and_should_retry_legacy (fixes #3484)
Co-authored-by: MervinPraison <[email protected]>
2026-07-28 17:16:01 +00:00
praisonai-triage-agent[bot]andMervinPraison e3c5cb18bb fix: restore retry tuning and compaction_strategy in ExecutionConfig.from_dict (fixes #3482)
Sync from_dict with to_dict so retry_initial_delay, retry_backoff_factor,
retry_jitter and compaction_strategy survive a to_dict/from_dict round-trip.
Also align code_sandbox_mode fallback with the dataclass default ("sandbox").

Co-authored-by: MervinPraison <[email protected]>
2026-07-28 17:15:30 +00:00
praisonai-triage-agent[bot] cb8a49fd11 Merge pull request #3481 from MervinPraison/claude/issue-3480-20260728-1621
fix: remove dead code noop and sanitize_agent_name_for_autogen_v4
2026-07-28 17:12:05 +00:00
praisonai-triage-agent[bot]andMervinPraison 0206e9dbc4 fix: remove dead code noop and sanitize_agent_name_for_autogen_v4 (fixes #3480)
Both helpers in the praisonai wrapper's agents_generator.py were defined
but referenced nowhere (no callers, no tests, not exported). Also drops
the now-unused `import keyword` used only by the removed function.

Co-authored-by: MervinPraison <[email protected]>
2026-07-28 16:22:02 +00:00
praisonai-triage-agent[bot] 508fab9598 Merge pull request #3478 from MervinPraison/claude/issue-3476-20260728-1012
fix: bot --browser uses praisonai-browser local automation
2026-07-28 12:34:28 +00:00
praisonai-triage-agent[bot] f0e62296ac Merge pull request #3477 from MervinPraison/claude/issue-3475-20260728-1011
fix: ASCII-safe safe_print() for Windows cp1252 playwright banners
2026-07-28 11:52:16 +00:00
MervinPraison 6b77c8758f docs: auto-update feature parity trackers [skip ci] 2026-07-28 11:10:38 +00:00
praisonai-triage-agent[bot] 23d8607376 Merge pull request #3474 from MervinPraison/claude/issue-3473-20260728-0947
fix: add isolated tool-calling bridge contract for code execution
2026-07-28 11:10:05 +00:00
praisonai-triage-agent[bot] f8760fd680 Merge pull request #3470 from MervinPraison/claude/issue-3468-20260728-0913
fix: validate gateway route/binding targets against agents map
2026-07-28 11:04:06 +00:00
praisonai-triage-agent[bot] 7b60380b79 Merge pull request #3466 from MervinPraison/claude/issue-3462-20260728-0850
fix: route free-text prompts with run-supported flags to the modern engine (fixes #3462)
2026-07-28 10:56:57 +00:00
praisonai-triage-agent[bot] f978b5a6ba Merge pull request #3465 from MervinPraison/claude/issue-3463-20260728-0850
fix: warm runtime hosts stateful per-session agents
2026-07-28 10:50:15 +00:00
praisonai-triage-agent[bot] 5141da6826 Merge pull request #3464 from MervinPraison/claude/issue-3461-20260728-0850
fix: interruptible interactive CLI turns via cooperative cancellation
2026-07-28 10:24:58 +00:00
praisonai-triage-agent[bot]andMervin Praison b866d76a8b fix: verify Playwright runtime and stop advertising unsupported browser profile
- browser_available() now requires the playwright runtime importable, not just
  praisonai_browser, so a base install without the Playwright extra falls back
  to the cloud BrowserBaseTool instead of selecting a local tool that fails at
  invocation (Greptile P1).
- create_browser_tool no longer advertises profile=X as active; PlaywrightBrowserAgent
  has no profile param and uses a fresh context, so the value is now logged as
  informational-only rather than misreported (Greptile P1).
- Add unit test covering the missing-Playwright fallback path.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-28 10:23:07 +00:00
praisonai-triage-agent[bot]andMervin Praison 7209b6d685 fix: support flush kwarg in safe_print for print drop-in parity
Addresses Greptile review: safe_print() advertised as a drop-in print
replacement but rejected flush=True. Add flush passthrough (guarded) plus
a regression test.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-28 10:19:56 +00:00
praisonai-triage-agent[bot]andDhivya-Bharathy 3eeee776d3 fix: bot --browser uses praisonai-browser local automation (fixes #3476)
BotHandler._build_tools() now prefers praisonai-browser's local Playwright
automation (navigate/snapshot/click) over cloud-only BrowserBaseTool when
capabilities.browser is set, honouring --browser-headless / --browser-profile.
Falls back to BrowserBaseTool only when praisonai-browser is unavailable.

Adds a lazy _browser_bridge (mirroring _code_bridge) and an agent-callable
browser_automate tool wrapping PlaywrightBrowserAgent.

Co-authored-by: Dhivya-Bharathy <[email protected]>
2026-07-28 10:17:04 +00:00
praisonai-triage-agent[bot] 942814d785 Merge pull request #3460 from MervinPraison/claude/issue-3459-20260728-0828
fix: harden managed_local write_file, pip install, and API key handling
2026-07-28 10:16:52 +00:00
praisonai-triage-agent[bot]andDhivya-Bharathy 2db514a372 fix: add ASCII-safe safe_print() for Windows cp1252 playwright banners (fixes #3475)
Adds safe_print() to praisonai_bot.gateway.unicode_utils so E2E harnesses and
console reporters can echo Playwright's "playwright install" banner (drawn with
box chars like U+2551) without crashing on default Windows cp1252 consoles.
Falls back to safe_error_message() sanitization only when the stream encoding
rejects the text, keeping the actionable hint readable instead of masking it
behind a secondary UnicodeEncodeError.

Co-authored-by: Dhivya-Bharathy <[email protected]>
2026-07-28 10:14:53 +00:00
praisonai-triage-agent[bot]andMervin Praison a51945a8c8 fix: forward invocation policy and limits across CodeToolBridge boundary
The CodeToolBridge.run_code(code) contract dropped the caller's per-run
allow-list, registry, timeout and max_output_size, so a transport could
only gate isolated tool calls by bridge-owned defaults — a weaker path
than the in-process executor and contrary to the "never a weaker path"
guarantee. Forward the invocation policy and limits to run_code so the
transport gates each call by exactly what the caller authorised.

- CodeToolBridge.run_code now takes allowed_tools/registry/timeout/
  max_output_size as keyword-only params (new protocol, no external
  implementers — fully backward compatible for existing callers).
- execute_code_with_tools forwards the invocation context to the bridge.
- Tests: recording bridge now uses only forwarded policy; added coverage
  for policy/limit propagation and forwarded-allow-list enforcement.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-28 09:58:42 +00:00
praisonai-triage-agent[bot]andMervinPraison 5d775542f8 fix: add isolated tool-calling bridge contract for code execution (fixes #3473)
Add a transport-agnostic CodeToolBridge protocol and parent-side
serve_tool_call helper in core, plus a backward-compatible bridge=
option on execute_code_with_tools. When a bridge is supplied, code runs
under isolation and reaches tools over the bridge (same allow-list +
approval gate); omitting it preserves today's in-process behaviour.

Concrete per-backend transports remain a follow-up in the sandbox layer;
core only defines the contract to stay lightweight.

Co-authored-by: MervinPraison <[email protected]>
2026-07-28 09:52:06 +00:00
praisonai-triage-agent[bot]andMervin Praison a9e47e7ba6 fix: reject blank route/binding targets in gateway validation
Empty-string targets were skipped by the `if target` truthiness check,
retaining the silent fallback/misroute this validation prevents. Skip
only None (omitted) so every supplied string target is validated.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-28 09:23:24 +00:00
praisonai-triage-agent[bot]andMervinPraison 3cf410c82f fix: validate gateway route/binding targets against agents map (fixes #3468)
Cross-check every channel's routes/routing targets (including default) and
bindings.agent against the declared agents: map in the canonical schema
validator. A typo now fails fast at load time (and in gateway doctor, which
loads via this schema) with the channel, bad target, and closest valid agent
id — instead of a silent logger.warning + misroute. Only enforced when
agents: is declared, so single-bot configs stay backward-compatible.

Co-authored-by: MervinPraison <[email protected]>
2026-07-28 09:18:22 +00:00
praisonai-triage-agent[bot]andMervin Praison d5d4ed1f08 fix: stub _get_session_agent in warm-runtime session event test
A run with session_id now routes to the stateful per-session agent
(_get_session_agent), not _get_agent. The test only stubbed _get_agent,
so it built a real Agent with no LLM backing and start() returned ''.
Stub the session builder too so the event fan-out contract is exercised
without a live LLM.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-28 09:10:01 +00:00
praisonai-triage-agent[bot]andMervin Praison fff67f0664 fix: value-aware flag classification so dash-prefixed option values route to modern engine
Fixes Greptile P1: a value-taking run option whose separated value begins
with a dash (e.g. `--session -abc`, `--output -json`) was mis-classified by
`_flag_names` as an unsupported flag, diverting an otherwise fully
run-supported prompt to the legacy engine and losing session continuity,
--output modes, the credential gate and permissions.

`_flag_names` now accepts the `value_opts` set and skips the token consumed
by a value-taking option (with `--opt=value` handled inline). `_looks_like_
bare_prompt` passes `run`'s value-taking options in, and short-circuits the
no-dash case before the (potentially heavy) run-option introspection.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-28 09:06:10 +00:00
praisonai-triage-agent[bot]andMervin Praison abef6d3ed9 fix: separate attach event id from session identity; guard model/continuity in warm runtime
Address 3 P1 review issues on the stateful warm-runtime session path:

- Attach id no longer replaces session identity: `run.py` passes the
  persistence/conversation id as `session_id` and the `--attach` label as a
  distinct `event_id`. A `--no-save --attach <id>` run streams events to the
  attach id but stays on the isolated anonymous path (no persistence).
- Model override rebuilds the session agent: the per-session warm agent is now
  keyed by the resolved model, so a later turn with a different model no longer
  silently runs the previous provider/model.
- Continuity-wiring failure is not cached: when session-store wiring fails, the
  turn runs one-shot but the unwired agent is not retained, so a later turn
  retries wiring instead of permanently serving an uncoupled agent.

Wrapper-only (praisonai-code); no core SDK changes, no new Agent params, no new
deps. Adds tests for model override, continuity-failure, and event/session id
separation; updates the attach mock to accept `event_id`.

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

Co-authored-by: Mervin Praison <[email protected]>
2026-07-28 09:05:30 +00:00
praisonai-triage-agent[bot]andMervin Praison c8f28d96d1 fix: wire primary TUI Ctrl-C to cancellation and guard abandoned worker
Address Greptile P1 findings on the interruptible-turn wrapper:

- Primary prompt-toolkit path now requests cooperative cancellation on
  Ctrl-C when a turn is in flight (previously only reset the input
  buffer), and clears any stale request at the start of each background
  turn so a fresh turn is not immediately interrupted.
- _execute_prompt_interruptible refuses to start a new turn (and to clear
  the shared controller) while a prior abandoned worker is still alive,
  preventing the abandoned turn from being un-cancelled and resuming
  against the warm session.
- Added test_abandoned_worker_blocks_new_turn.

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

Co-authored-by: Mervin Praison <[email protected]>
2026-07-28 09:02:26 +00:00
praisonai-triage-agent[bot]andMervinPraison 7cb8f71f82 fix: route free-text prompts with run-supported flags to the modern engine (fixes #3462)
The CLI router treated any -/-- flag as a signal to fall back to the legacy
argparse engine, so common cases like `praisonai "fix the bug" --model gpt-4o`,
`--continue`, or `--output json` silently bypassed the modern `run` engine and
lost session continuity, --output modes, the credential gate and permissions.

_looks_like_bare_prompt now derives the run-supported option names by
introspecting the run command's Click parameters and routes a bare prompt to
`run` when every flag present is one run accepts; genuinely legacy-only flags
(and .yaml/.yml workflows) still fall back to legacy, now with a one-line
notice so the fallback is never silent. _build_run_argv reconstructs the
prompt + flags into a single `run "<prompt>" <flags>` invocation.

Co-authored-by: MervinPraison <[email protected]>
2026-07-28 08:58:10 +00:00
praisonai-triage-agent[bot]andMervinPraison 447eb8db4e fix: warm runtime hosts stateful per-session agents (fixes #3463)
The warm runtime was a cold-start cache only: every /run cleared history
and --continue/--session runs bypassed the warm path, paying cold-start
each turn. Add a per-session warm agent registry keyed by session id that
rehydrates history once (via the existing apply_cli_session_continuity
wiring) and retains it across turns, while the anonymous path stays
isolated. Relax runtime_eligible so --continue/--session route to the warm
stateful path (fork/isolated/thinking/tool runs stay in-process).

Co-authored-by: MervinPraison <[email protected]>
2026-07-28 08:56:01 +00:00
praisonai-triage-agent[bot]andMervinPraison 6b849b4c40 fix: wire interactive TUI Ctrl-C to cooperative cancellation (fixes #3461)
Attach the core InterruptController to the interactive agent and run each
turn in a worker thread so the main thread stays responsive. Ctrl-C during
a turn now requests cooperative cancellation; the core chat loop honours it
at the next step boundary, returns partial output, and keeps the warm agent
and session intact. Wrapper-only change reusing the existing core primitive.

Co-authored-by: MervinPraison <[email protected]>
2026-07-28 08:54:44 +00:00
praisonai-triage-agent[bot]andMervinPraison cc6994764d fix: harden managed_local write_file, pip install, and API key handling (fixes #3459)
- write_file compute bridge: replace heredoc with base64-decoded stdin so
  content can no longer terminate the heredoc early (silent truncation) or
  inject host commands.
- LocalCompute._install_packages: validate pip specifiers against the strict
  allowlist and shlex.quote each token before host execution.
- LocalManagedAgent._ensure_agent: pass api_key/base_url directly to the inner
  Agent instead of os.environ.setdefault, preventing process-wide credential
  pollution and subprocess env leakage across tenants.

Co-authored-by: MervinPraison <[email protected]>
2026-07-28 08:31:21 +00:00
praisonai-triage-agent[bot] b43688ad95 Merge pull request #3454 from MervinPraison/claude/issue-3453-20260727-1618
fix: make tools discover resolver-first, manual scan as fallback
2026-07-27 17:40:01 +00:00
praisonai-triage-agent[bot]andMervin Praison 482c0781b1 fix: remove unused --entrypoints flag from tools discover
The --entrypoints option was documented and parsed into use_entrypoints
but never wired to any discovery behavior. Removed the dead flag and
updated the docstring to reflect the actual --include-only interface.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-27 16:26:41 +00:00
praisonai-triage-agent[bot]andMervinPraison 98f2cc440b fix: make tools discover resolver-first, manual scan as fallback (fixes #3453)
action_discover now reads built-in/external/registered/local from the
canonical ToolResolver.list_available_sources() in a single authoritative
walk, matching the resolver-first pattern already used by _get_builtin_tools
and templates/tools_doctor.py. The original praisonai_tools + TOOL_MAPPINGS
scan is preserved as an explicit offline fallback (_legacy_manual_scan) for
environments without praisonai-code. --include/--entrypoints flags and
grouped output are unchanged.

Co-authored-by: MervinPraison <[email protected]>
2026-07-27 16:20:41 +00:00
MervinPraison 30c44e3cce docs: auto-update documentation parity trackers [skip ci] 2026-07-27 11:22:40 +00:00
praisonai-triage-agent[bot] 80e53f1398 Merge pull request #3451 from MervinPraison/claude/issue-3450-20260727-1020
fix: resolve BaseTool instances in async tool dispatch (fixes #3450)
2026-07-27 11:22:06 +00:00
praisonai-triage-agent[bot] 2011cf2edf Merge pull request #3449 from MervinPraison/claude/issue-3444-20260727-0945
fix: make scheduled-job delivery continuable by default
2026-07-27 11:09:40 +00:00
praisonai-triage-agent[bot] 11b564461e Merge pull request #3436 from MervinPraison/claude/issue-3431-20260727-0903
fix: bootstrap praisonai-mcp sibling for MCP wrapper unit tests
2026-07-27 11:08:40 +00:00
MervinPraison db738fb465 docs: auto-update documentation parity trackers [skip ci] 2026-07-27 11:01:40 +00:00
praisonai-triage-agent[bot] c806bc9ebb Merge pull request #3448 from MervinPraison/claude/issue-3445-20260727-0945
fix: add memory-aware gateway admission control (#3445)
2026-07-27 11:01:05 +00:00
praisonai-triage-agent[bot] d4359d70d4 Merge pull request #3433 from MervinPraison/claude/issue-3428-20260727-0903
fix: replace emoji with ASCII status tags in terminal-bench smoke script
2026-07-27 10:53:17 +00:00
praisonai-triage-agent[bot] 3a55c7876e Merge pull request #3447 from MervinPraison/claude/issue-3446-20260727-0946
fix: make outbound reply delivery crash-safe by default (#3446)
2026-07-27 10:52:55 +00:00
MervinPraison eaab4cba09 docs: auto-update documentation parity trackers [skip ci] 2026-07-27 10:41:06 +00:00
praisonai-triage-agent[bot] 7a96c092cc Merge pull request #3443 from MervinPraison/claude/issue-3439-20260727-0930
fix: typed gateway-runtime contract for channel adapters
2026-07-27 10:40:34 +00:00
praisonai-triage-agent[bot]andMervin Praison 3bfcd189f2 fix: carry BaseTool resolution through async execution + aliased names
Downstream _execute_tool_async_impl matched only on __name__ and called
func(**args) directly, so a BrowserBaseTool-style BaseTool instance
(resolved by .name in dispatch) returned "not found" / never ran. Mirror
the robust sync resolution (BaseTool.name, FunctionTool .name alias, class
name) and invoke func.run() for BaseTool instances.

Also fix the short-circuiting `or` chain in async dispatch so an aliased
.name that differs from __name__ resolves instead of being dropped.

Adds regression tests exercising the real (unmocked) execute_tool_async
for a BaseTool instance and an aliased callable name.

Fixes #3450

Co-authored-by: Mervin Praison <[email protected]>
2026-07-27 10:32:45 +00:00
praisonai-triage-agent[bot]andMervin Praison 2f2713718a fix: skip MCP wrapper tests cleanly when praisonai-mcp source is unavailable
Address CodeRabbit review: when neither the monorepo praisonai-mcp sibling
nor an installed praisonai_mcp.mcp_server is available, the C12 shim cannot
resolve. Convert the resulting bare ModuleNotFoundError collection error into
a clean module-level pytest.skip. Guard find_spec against ModuleNotFoundError/
ValueError for an absent/broken parent, mirroring praisonai._bootstrap.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-27 10:30:16 +00:00
praisonai-triage-agent[bot] 4321d5c203 Merge pull request #3432 from MervinPraison/claude/issue-3425-20260727-0854
fix: skip MCP wrapper unit tests cleanly when praisonai-mcp absent
2026-07-27 10:26:56 +00:00
praisonai-triage-agent[bot]andDhivya-Bharathy b13a7c4bfb fix: resolve BaseTool instances in async tool dispatch (fixes #3450)
Bot --browser wired BrowserBaseTool (a BaseTool instance without
__name__), causing async tool dispatch to raise
'BrowserBaseTool' object has no attribute '__name__'. Harden the
lookup in _achat_completion to resolve by __name__, .name, or class
name so all BaseTool subclasses dispatch safely, and drop the ad-hoc
__name__ monkey-patch in bots_cli.

Co-authored-by: Dhivya-Bharathy <[email protected]>
2026-07-27 10:24:40 +00:00
praisonai-triage-agent[bot] 7b4ee9b058 Merge pull request #3434 from MervinPraison/claude/issue-3426-20260727-0900
feat: add opt-in transcript redaction to session export
2026-07-27 10:20:39 +00:00
praisonai-triage-agent[bot] 4505776fb3 Merge pull request #3435 from MervinPraison/claude/issue-3430-20260727-0904
fix: map box-drawing chars in bot error sanitizer for cp1252 (#3430)
2026-07-27 10:07:37 +00:00
praisonai-triage-agent[bot]andMervin Praison edef7d0468 fix: harden memory-aware admission (Windows import, production wiring)
- Guard Unix-only ``resource`` import so _admission.py loads on Windows;
  sampler self-disables gracefully when unavailable (Greptile P1 #1).
- Wire ``max_rss_mb`` through BotOS + gateway.yaml via a single-knob
  build_memory_pressure_policy() so the feature has a live production
  consumer instead of a dormant param (Greptile P1 #3).
- Surface max_rss_mb in admission stats; document resource-only soft-queue
  degradation honestly rather than silently misleading (Greptile P1 #2).
- Correct MemoryPressurePolicy docstring to reference the real config key.
- Add tests: Windows-safe sampler, single-knob policy, BotOS wiring, stats.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-27 10:04:22 +00:00
praisonai-triage-agent[bot]andMervin Praison ce285a8e96 fix: preserve schedule_add positional arg order for backward compat
Move the new continuable param to the end of schedule_add() so the
pre-existing 9th positional slot still binds accept_suggestion, avoiding
a silent behaviour change for positional callers (Greptile P1).

Co-authored-by: Mervin Praison <[email protected]>
2026-07-27 09:59:54 +00:00
praisonai-triage-agent[bot]andMervin Praison 7755da50a4 fix: recover outbound DLQ init on transient storage failure (#3446)
A transient DLQ-init failure no longer latches _outbound_resilience_ready,
so a later delivery re-attempts initialization once storage recovers,
instead of permanently degrading to retry-only and silently dropping
permanently-failed replies. Adds a regression test.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-27 09:59:43 +00:00
praisonai-triage-agent[bot]andMervin Praison 410d169d28 fix: make exception text ASCII-safe with ascii(e) in smoke script
Runtime exception messages could contain non-cp1252 characters that
would re-trigger UnicodeEncodeError on Windows consoles when printed.
Wrap exception interpolation in ascii() for all 7 failure messages.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-27 09:58:54 +00:00
praisonai-triage-agent[bot] 09cf8f8d11 Merge pull request #3429 from MervinPraison/claude/issue-3423-20260727-0852
fix: replace emoji with ASCII tags in terminal_bench smoke script for Windows cp1252
2026-07-27 09:55:28 +00:00
MervinPraison 9adf9f3c25 docs: auto-update documentation parity trackers [skip ci] 2026-07-27 09:53:40 +00:00
praisonai-triage-agent[bot] 112e61c4b3 Merge pull request #3326 from MervinPraison/claude/issue-3307-20260723-1028
fix: async loop expansion, tool-tracking race, MCP skill-gate (#3307)
2026-07-27 09:52:19 +00:00
praisonai-triage-agent[bot]andMervinPraison ae592fc111 fix: make scheduled-job delivery continuable by default (fixes #3444)
A delivered automated brief now seeds a resumable session so the user's
reply in the same chat resumes the job's conversation with full context,
instead of landing as a contextless new turn.

- core: add declarable DeliveryTarget.continuable field (opt-out only,
  round-tripped in to_dict/from_dict) as the 3-way surface contract
- wrapper: gateway _deliver_scheduled_result seeds the reply session via
  the existing mirror_to_session path when continuable
- tool/CLI: thread continuable through schedule_add + a --no-continuable
  flag for fire-and-forget notices

Co-authored-by: MervinPraison <[email protected]>
2026-07-27 09:51:54 +00:00
praisonai-triage-agent[bot]andMervinPraison a62c671d62 fix: add memory-aware gateway admission control (fixes #3445)
Gateway admission was concurrency/CPU-scaled only and blind to memory, so a
burst of concurrent turns on a small always-on host drives RSS up until the
OOM killer fires — observed only post-mortem. This adds a resource-pressure
policy that queues under soft RSS pressure and sheds under hard pressure,
reusing the existing admission seam.

Core (praisonaiagents/gateway): ResourceSample, ResourcePressurePolicyProtocol
and a stdlib-first MemoryPressurePolicy (pure decision, no heavy imports),
sitting beside the concurrency / rate-limit / scale-to-zero policy family.

Wrapper (praisonai_bot/bots/_admission.py): a lightweight _RssSampler
(psutil-optional, resource.getrusage fallback, self-disables on unsupported
platforms) and AdmissionGate(resource_policy=...) wiring that folds the
resource decision into admit() by escalating to the more restrictive outcome.

Co-authored-by: MervinPraison <[email protected]>
2026-07-27 09:51:46 +00:00
praisonai-triage-agent[bot]andMervinPraison 5c80362d6b fix: make outbound reply delivery crash-safe by default (fixes #3446)
Mirror the durable inbound journal on the outbound side: when no
outbound DLQ path is configured, default to the canonical per-platform
store (~/.praisonai/state/<platform>/outbound_dlq.sqlite) so a
permanently-failed or exhausted reply is parked (auditable + replayable)
instead of silently dropped. Escape hatch: outbound_resilience.enabled=false.

Co-authored-by: MervinPraison <[email protected]>
2026-07-27 09:50:21 +00:00
praisonai-triage-agent[bot] 574c060b0a Merge pull request #3422 from MervinPraison/claude/fix-praisonai-yaml-config-name-20260727
fix: use canonical praisonai.yaml as project config name (with praison.yaml fallback)
2026-07-27 09:48:40 +00:00
praisonai-triage-agent[bot]andMervin Praison 9dcddf1b19 fix: gateway-runtime contract falls back to legacy splices on older core
The wrapper permits a range of praisonaiagents versions (>=1.6.152), but
_attach_gateway_runtime imported GatewayRuntimeSeams/GatewayAdapterContractError
unconditionally — symbols only present in current core. On an older-but-allowed
core that import raised ImportError on every start()/probe()/health() (Greptile
P1). Guard the import and fall back to the pre-contract duck-typed splices so
those installs keep wiring identity resolution, delivery routing, admission
control, and cross-platform turn locking. The no-seams path now returns before
any import, staying a pure no-op independent of core version.

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

Co-authored-by: Mervin Praison <[email protected]>
2026-07-27 09:48:01 +00:00
praisonai-triage-agent[bot] 61e8c1ec56 Merge pull request #3421 from MervinPraison/claude/issue-3420-20260727-0822
fix: scheduler async-drift, unlocked template cache, scheduled-YAML tool bypass (fixes #3420)
2026-07-27 09:46:05 +00:00
praisonai-triage-agent[bot]andMervinPraison db15240a11 fix: give channel adapters a typed gateway-runtime contract (fixes #3439)
Replace the four duck-typed private-attribute splices in Bot._build_adapter
(identity resolver, delivery router, admission gate, per-turn lock map) with an
explicit core Protocol. A missing contract now fails loudly instead of silently
dropping admission control, delivery routing and cross-platform turn locking.

- core: add GatewayRuntimeSeams, SupportsGatewayRuntime, GatewayAdapterContractError
- praisonai-bot: BotSessionManager.attach_gateway_runtime implements the contract
- praisonai-bot: Bot._attach_gateway_runtime calls the typed seam once

Co-authored-by: MervinPraison <[email protected]>
2026-07-27 09:36:11 +00:00
praisonai-triage-agent[bot]andMervin Praison baa1222dc1 fix: close redaction gaps in session export sanitise (#3426)
- Legacy-only sessions now honour --sanitise instead of returning a raw
  verbatim transcript, closing a secret-leak gap.
- Enforce --redact-level contract: validate against REDACT_LEVELS (standard|
  strict), reject typos at the CLI, and give strict a real effect (masks
  bearer tokens and PEM private-key blocks).
- Path matcher now covers single-segment POSIX (/tmp), C:/ Windows, and UNC
  (\\server\share) paths; the cwd is masked as a stable path placeholder so it
  is no longer half-masked as a secret leaving a dangling suffix.
- Add tests for single-segment/UNC paths, cwd suffix, strict mode, invalid
  level, and exported REDACT_LEVELS.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-27 09:24:38 +00:00
praisonai-triage-agent[bot]andMervin Praison 3cd823d4e2 fix: probe praisonai_mcp.mcp_server submodule and report skip reason
Address CodeRabbit review on MCP test conftest:
- Check the shim's required praisonai_mcp.mcp_server submodule instead of only
  the top-level package, so a partial/incompatible install can't pass the guard
  while collection still fails.
- Emit a pytest_report_header when MCP tests are skipped so contributors see why
  and how to install praisonai-mcp.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-27 09:08:35 +00:00
praisonai-triage-agent[bot]andDhivya-Bharathy ba1e97cdbb fix: map box-drawing chars in bot error sanitizer for cp1252 (fixes #3430)
Playwright's "playwright install" banner uses box-drawing frame characters
(U+2551 etc.). On Windows cp1252 consoles these could clutter the sanitized
error text with '?' placeholders, obscuring the actionable hint. Map the
common frame characters to spaces in safe_error_message's symbol table so the
hint stays readable while remaining ASCII-safe.

Co-authored-by: Dhivya-Bharathy <[email protected]>
2026-07-27 09:06:58 +00:00
praisonai-triage-agent[bot]andMervinPraison d1b6d38b75 feat: add opt-in transcript redaction to session export (fixes #3426)
Add a lightweight, deterministic redactor so `praisonai session export
<id> --sanitise` (alias `--sanitize`) replaces secrets, absolute paths,
the working directory, and embedded file contents with stable
`[redacted:<category>:<n>]` placeholders. Default export is unchanged.

- new redact.py helper with stable placeholder map (stdlib only)
- wire redact/redact_level through export_session (Python: redact=True)
- wire --sanitise/--sanitize + --redact-level CLI flags, default off
- unit tests over a seeded secret, absolute path, and stable placeholders

Co-authored-by: MervinPraison <[email protected]>
2026-07-27 09:05:09 +00:00
praisonai-triage-agent[bot]andDhivya-Bharathy e474e0cd5c fix: skip MCP wrapper unit tests cleanly when praisonai-mcp absent (fixes #3425)
Add tests/unit/mcp/conftest.py that restores the monorepo dev layout via
ensure_praisonai_mcp() and uses collect_ignore_glob to skip the directory
when praisonai_mcp is neither installed nor present as a sibling checkout,
turning a ModuleNotFoundError collection error into a clean no-op.

Co-authored-by: Dhivya-Bharathy <[email protected]>
2026-07-27 08:56:59 +00:00
praisonai-triage-agent[bot]andDhivya-Bharathy d4e3461d37 fix: replace emoji with ASCII tags in terminal_bench smoke script for Windows cp1252 (fixes #3423)
The basic smoke script crashed with UnicodeEncodeError on Windows
default consoles (cp1252) because print() statements embedded emoji
(U+1F9EA, U+2705, U+274C, U+1F389) that cannot be encoded to stdout.

Replace all emoji with ASCII status tags ([TEST], [OK], [FAIL]) so the
script runs on any terminal encoding without decoration loss.

Co-authored-by: Dhivya-Bharathy <[email protected]>
2026-07-27 08:54:06 +00:00
praisonai-triage-agent[bot]andMervin Praison a8d73265c6 test: cover .yml extensions and canonical-over-legacy precedence for project config
Addresses CodeRabbit nitpick: add praisonai.yml / legacy praison.yml
discovery tests and a precedence test asserting canonical praisonai.yaml
wins over legacy praison.yaml when both are present.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-27 08:53:16 +00:00
praisonai-triage-agent[bot]andLeebana e4179b412d fix: add canonical praisonai.yaml as project config name
The praisonai-code resolver only searched for `praison.yaml` at the
project root, which is inconsistent with the agents SDK loader
(`praisonaiagents/config/loader.py`) that uses the canonical
`praisonai.yaml`. Add `praisonai.yaml`/`praisonai.yml` as the primary
project-root names while retaining `praison.yaml`/`praison.yml` for
backward compatibility, and update the docstring reference. Adds
regression tests covering both the canonical and legacy names.

Co-authored-by: Leebana <[email protected]>
2026-07-27 08:47:09 +00:00
praisonai-triage-agent[bot]andMervin Praison d15657ba21 fix(skills): read MCP server registry live to avoid stale STRICT gate
CapabilityValidator cached the MCP server snapshot once, so servers that
connected after the first validation stayed invisible under STRICT
enforcement. Read the process-level registry live each call (cheap
set-copy under lock); tool cache is unchanged. (#3307)

Co-authored-by: Mervin Praison <[email protected]>
2026-07-27 08:44:31 +00:00
praisonai-triage-agent[bot]andMervin Praison b19e4da70b fix: async loop expansion, tool-tracking race, MCP skill-gate (fixes #3307)
Gap 1: port loop-task pre-expansion from workflow() into aworkflow() so
async workflows with a CSV-driven loop start task expand per-row instead
of running once.

Gap 2: guard the per-turn _turn_tools_used buffer with the same
AsyncSafeState lock that protects chat_history, routing all sites through
_reset/_record/_drain helpers so concurrent chat()/achat() turns on one
Agent no longer corrupt hook/self-improve tool data. Backward-compatible
_turn_tools_used property retained.

Gap 3: track namespaced MCP server names in a process-level registry
(MCP.list_active_server_names(), populated in with_tool_prefix) and read
it from CapabilityValidator._get_available_servers so MCP-server-gated
skills can pass STRICT validation instead of always failing closed.

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

Co-authored-by: Mervin Praison <[email protected]>
2026-07-27 08:44:31 +00:00
MervinPraison 54b43340f5 docs: auto-update api.md [skip ci] 2026-07-27 08:43:41 +00:00
Leebana febdd8ec6e Merge pull request #3419 from MervinPraison/claude/issue-3418-20260727-0714
fix: shared-port endpoints, async memory init, MongoDB short-term embeddings
2026-07-27 09:42:48 +01:00
Leebana 1a372f6e41 Merge pull request #3417 from MervinPraison/claude/issue-3415-20260726-1713
fix: defer eager import json in _logging.py to structured-logging call site
2026-07-27 09:42:27 +01:00
Leebana cd56c59551 Merge pull request #3399 from Hore01/fix-stop-project-config-home-walkup
fix: stop project config discovery at home directory
2026-07-27 09:41:54 +01:00
Leebana ebd27167a7 Merge pull request #3396 from MervinPraison/feat/praisonai-train-mtp
feat(train): MTP fast-inference for Gemma-4 (self-speculative decoding, +1.40x measured)
2026-07-27 09:40:59 +01:00
Leebana 02631d69d6 Merge pull request #3394 from MervinPraison/claude/issue-3392-20260725-1712
fix: remove dead import logging from ~110 core modules
2026-07-27 09:40:11 +01:00
Leebana 2ce4228e3d Merge pull request #3371 from MervinPraison/claude/issue-3368-20260725-0716
fix: async-safe handoff chain, session read-error data safety, per-agent approval scoping
2026-07-27 09:39:35 +01:00
Leebana 3b7e2c8875 Merge pull request #3367 from MervinPraison/feat/praisonai-train-robustness
feat(train): non-developer robustness — clean errors, preflight, export command, Ollama/GGUF/HF failure handling
2026-07-27 09:39:13 +01:00
Leebana 2bb18e8e59 Merge pull request #3366 from MervinPraison/claude/issue-3364-20260724-1713
refactor: extract duplicate MCP to_openai_tool() into shared helper
2026-07-27 09:38:54 +01:00
Leebana b047d92040 Merge pull request #3365 from MervinPraison/claude/issue-3363-20260724-1712
fix: reuse canonical token heuristic in compaction fallback
2026-07-27 09:38:37 +01:00
Leebana 8d4b8d15a4 Merge pull request #3357 from MervinPraison/claude/issue-3355-20260724-1419
fix: root /undo at the bot workspace, not process cwd (#3355)
2026-07-27 09:38:19 +01:00
praisonai-triage-agent[bot]andMervin Praison f0c733710c fix: close cache put/clear race and async zero-budget false start (#3420)
Address reviewer-flagged concurrency gaps in the scheduler + template cache:

- TemplateCache locks are now process-wide (class-level, keyed by path) so two
  independent instances over the same dir coordinate; get() reads under the
  per-key lock so it never observes the intermediate two-rename window; put()/
  invalidate() take root+key locks and clear() takes the root lock, so a
  concurrent clear() can no longer rmtree a half-written entry. put() stages
  into a reserved .staging subdir (same fs, atomic os.replace) that clear()
  skips, eliminating the put-vs-clear FileNotFoundError.
- AsyncAgentScheduler.start() no longer reports a successful start (and no
  longer spins up a background task) when the immediate run trips the budget
  brake (e.g. max_cost=0), matching the actually-stopped state.

Verified: 4 writer/clearer + 2 reader concurrency smoke test -> 0 races;
zero-budget start returns False with no task; 335 scheduler+template tests pass.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-27 08:38:02 +00:00
Leebana 9f08e27d15 Merge pull request #3353 from MervinPraison/claude/issue-3352-20260724-0942
fix: prompt-cache-stability contract for the gateway
2026-07-27 09:37:49 +01:00
MervinPraison 6507559279 docs: auto-update feature parity trackers [skip ci] 2026-07-27 08:37:28 +00:00
Leebana 33584899a9 Merge pull request #3343 from Dhivya-Bharathy/fix/e2e-examples-batch4
fix: resolve 4 remaining E2E example failures after batch-3 merge
2026-07-27 09:36:58 +01:00
Leebana cbfff02451 Merge pull request #3342 from MervinPraison/feat/gateway-diagnostics-upgrade
feat(gateway): tiered diagnostics for runtime, inbound, and duplicates
2026-07-27 09:36:43 +01:00
MervinPraison 8b675d3ed0 docs: auto-update api.md [skip ci] 2026-07-27 08:35:55 +00:00
Leebana f21ec569a5 Merge pull request #3319 from MervinPraison/claude/issue-3307-20260723-1021
fix: aworkflow loop expansion, concurrent turn-tool race, MCP skill-gate discovery
2026-07-27 09:35:29 +01:00
praisonai-triage-agent[bot]andMervinPraison 9d831532ab fix: close scheduler async-drift, cache race, scheduled-YAML tool gaps (fixes #3420)
- Async scheduler now honours the intentional-silence marker on delivery
  (shared _should_suppress_delivery on _BaseAgentScheduler); removes the
  duplicate budget guard, replacing both with a single _budget_exceeded()
  helper that treats max_cost=0 as a real zero budget.
- TemplateCache.put()/invalidate() now stage into a sibling temp dir and
  atomically os.replace() under a per-key lock, so concurrent readers never
  observe a half-populated or mid-rmtree cache entry (multi-agent/interprocess).
- Scheduled agents.yaml tools now resolve through the canonical ToolResolver
  (same path as `praisonai run`), instead of dropping everything but a
  hardcoded search_tool — keeping CLI/YAML/Python behaviour identical.

Co-authored-by: MervinPraison <[email protected]>
2026-07-27 08:28:18 +00:00
praisonai-triage-agent[bot]andMervin Praison 0729bd5c47 fix: prevent async event-loop block on failed memory init; refresh OpenAPI cache on shared-port launch
- agents.py: _build_execution_context gains skip_memory_init; aexecute_task
  passes True so a failed initialize_memory_async() no longer falls through
  to the synchronous initialize_memory() on the event-loop thread.
- execution_mixin.py: reset app.openapi_schema after registering a shared-port
  route so later launch() calls appear in /openapi.json and /docs.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-27 07:27:09 +00:00
praisonai-triage-agent[bot]andMervinPraison eed2ada270 fix: shared-port endpoints, async memory init, MongoDB short-term embeddings (fixes #3418)
- Agent.launch(): register every path (not only first per port) and move the
  keep-alive loop outside _server_lock so a second agent on a shared port is
  no longer silently dropped and the process-wide lock isn't held forever.
- aexecute_task(): initialize memory via initialize_memory_async() to avoid
  blocking the shared event loop on synchronous Memory() construction.
- MongoDBMemoryAdapter: factor embedding logic into shared _store/_search
  helpers so short-term memory also gets/uses embeddings when
  use_vector_search=True, matching the long-term tier.

Co-authored-by: MervinPraison <[email protected]>
2026-07-27 07:20:36 +00:00
praisonai-triage-agent[bot]andMervinPraison f51f8ecdab fix: remove dead import logging from ~110 core modules (fixes #3392)
These modules log exclusively via get_logger and never reference the
logging. namespace; the standalone import logging is dead code left over
from the get_logger migration. Removed it only where logging. is never
referenced (111 files); files that genuinely use logging. are untouched.

Co-authored-by: MervinPraison <[email protected]>
2026-07-26 17:58:20 +00:00
MervinPraison f2ff1c8f8c docs: auto-update documentation parity trackers [skip ci] 2026-07-26 17:56:32 +00:00
praisonai-triage-agent[bot] ceebb5d8e6 Merge pull request #3416 from MervinPraison/claude/issue-3414-20260726-1713
fix: remove orphaned FastContext dead code (file_watcher.py + search_strategy.py)
2026-07-26 17:56:01 +00:00
praisonai-triage-agent[bot] 2c57dc4559 Merge pull request #3413 from MervinPraison/claude/issue-3412-20260726-1623
fix: remove dead duplicate get_available_integrations() in registry.py
2026-07-26 17:23:34 +00:00
praisonai-triage-agent[bot]andMervin Praison 48579bde51 fix: defer eager import json in _logging.py to structured-logging call site (fixes #3415)
Co-authored-by: Mervin Praison <[email protected]>
2026-07-26 17:14:50 +00:00
praisonai-triage-agent[bot]andMervin Praison 2f11a6a53e fix: remove orphaned FastContext dead code (fixes #3414)
Delete two unreachable modules under context/fast/ that are never
imported, exported, or referenced anywhere in the SDK, tests, examples,
or docs:
- indexer/file_watcher.py (FileWatcher, IncrementalIndexer, ...)
- search_strategy.py (SearchStrategy, SearchState, SearchPhase)

Grep confirms only the definition sites matched; no importers exist.
Live FastContext path (fast_context, search_backends, parallel_executor,
indexer/file_indexer, symbol_indexer) is unchanged. No __init__.py edits
needed since neither module is exported.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-26 17:14:31 +00:00
praisonai-triage-agent[bot]andMervin Praison 2c469c5a60 docs: drop stale get_available_integrations() mention from registry docstring
Co-authored-by: Mervin Praison <[email protected]>
2026-07-26 16:28:19 +00:00
praisonai-triage-agent[bot]andMervinPraison ce7ce9f047 fix: remove dead duplicate get_available_integrations() in registry.py (fixes #3412)
The registry.py copy of get_available_integrations() was unreferenced dead
code duplicating the canonical base.py implementation. The public symbol is
exported from integrations/__init__.py and lazily resolved via
_unified_registry.py, which binds to the base.py version. No importer, no
__all__ entry, and no internal caller referenced the registry.py copy.

Co-authored-by: MervinPraison <[email protected]>
2026-07-26 16:24:28 +00:00
MervinPraison a5ecf28b8e docs: auto-update api.md [skip ci] 2026-07-26 11:36:49 +00:00
praisonai-triage-agent[bot] 866913581c Merge pull request #3405 from MervinPraison/claude/issue-3403-20260726-0852
fix: structured NDJSON stream events for YAML/AgentTeam runs
2026-07-26 11:36:22 +00:00
praisonai-triage-agent[bot] c010e0c07b Merge pull request #3411 from MervinPraison/claude/issue-3410-20260726-0946
fix: wire opt-in event-loop liveness watchdog into gateway
2026-07-26 11:01:46 +00:00
MervinPraison bc35bbb78e docs: auto-update api.md [skip ci] 2026-07-26 10:44:33 +00:00
praisonai-triage-agent[bot] b56a78eed7 Merge pull request #3409 from MervinPraison/claude/issue-3407-20260726-0914
fix: SQLite-backed transcript store for concurrent gateways
2026-07-26 10:44:10 +00:00
praisonai-triage-agent[bot]andMervin Praison 6299a03459 fix: wire prompt-cache metrics, clear stale signatures, detect tool schema drift (#3352)
Address three P1 review findings on the prompt-cache-stability contract:

- Wire GatewayMetrics into per-bot sessions via a new _stamp_metrics splice
  (mirrors _stamp_admission_gate/_stamp_identity_resolver), called from both
  start_channels and hot-reload, so prompt_cache_invalidations_total actually
  increments in production instead of staying zero.
- Clear _prefix_sig in every session-clear path (_clear_session_data,
  reap_stale, reset_all) so a reopened session establishes a fresh baseline
  instead of emitting a false PROMPT_PREFIX_INVALIDATED against the old one.
- Fingerprint the full provider-visible tool schema (name + description +
  parameters for dict tools, name + docstring for callables) instead of only
  tool names, so a same-name schema edit is detected. Best-effort; never raises.

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

Co-authored-by: Mervin Praison <[email protected]>
2026-07-26 10:39:42 +00:00
praisonai-triage-agent[bot]andMervinPraison 751998e36e fix: add prompt-cache-stability contract for the gateway (fixes #3352)
Core (praisonaiagents): new advisory HookEvent.PROMPT_PREFIX_INVALIDATED
and a pure prompt_prefix_signature(agent) that fingerprints only the
cache-relevant prefix (model + sorted tool names + system-prompt fp),
excluding volatile per-turn data. Kept out of agent.py to avoid bloat.

Wrapper/bot: BotSessionManager computes the signature after its per-turn
tool/model swaps, meters drift via an optional prompt_cache_invalidations_total
GatewayMetrics counter, and fires the advisory hook so silent provider
prompt-cache misses on long-lived conversations become auditable.

Co-authored-by: MervinPraison <[email protected]>
2026-07-26 10:39:42 +00:00
MervinPraison c9cdedfb61 docs: auto-update feature parity trackers [skip ci] 2026-07-26 10:36:10 +00:00
praisonai-triage-agent[bot] dd39391090 Merge pull request #3408 from MervinPraison/claude/issue-3406-20260726-0914
fix: add canonical RunOutcome terminal-outcome for agent runs
2026-07-26 10:35:46 +00:00
praisonai-triage-agent[bot]andMervin Praison 5df9114444 fix: emit terminal run.error on failed AgentTeam stream-json run
When team.astart() raises during a YAML/AgentTeam `--output stream-json`
run, the adapter now emits a terminal run.error event (best-effort,
without masking the original exception) before detaching the bridge,
matching the single-agent path's contract so consumers can distinguish
a failed run from an incomplete/still-running one. Fixes greptile P1.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-26 10:30:48 +00:00
praisonai-triage-agent[bot]andMervinPraison f4690e2fdd fix: emit per-agent NDJSON stream events for YAML/AgentTeam runs (fixes #3403)
AgentTeam now exposes a lazy aggregate stream_emitter that fans in member
agents' StreamEventEmitter events, tagging each with the emitting agent's
agent_id. The PraisonAI adapter attaches the CLI stream-json bridge to this
team emitter around team.astart(), so `--output stream-json` on a YAML/team
run emits the same per-agent, per-step NDJSON stream as single-agent runs.
Both paths are zero-overhead no-ops outside structured output mode.

Co-authored-by: MervinPraison <[email protected]>
2026-07-26 10:30:48 +00:00
praisonai-triage-agent[bot] acdfc4189c Merge pull request #3404 from MervinPraison/claude/issue-3402-20260726-0852
fix: CLI session continuity for YAML/AgentTeam runs
2026-07-26 10:27:49 +00:00
praisonai-triage-agent[bot]andClaude 0c72663ea8 fix: expose --watchdog flags on active Typer gateway start command (#3410)
The event-loop liveness watchdog flags were only registered on the legacy
argparse parser in cli/features/gateway.py, which the real
`praisonai gateway start` Typer entrypoint (cli/commands/gateway.py) never
uses — so `--watchdog` / `--watchdog-timeout` were rejected at the primary
opt-in surface. Add both options to the Typer command and forward them to
GatewayHandler.start using the same None-means-fall-back-to-YAML convention
as the other store_true flags. `restart` already replays them via the
persisted start-flags. Adds 3 CLI-surface tests.

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

Co-Authored-By: Claude <[email protected]>
2026-07-26 10:01:36 +00:00
praisonai-triage-agent[bot]andMervinPraison d745fde198 fix: wire opt-in event-loop liveness watchdog into gateway (fixes #3410)
Arm the existing core LoopWatchdog (#3385) around the gateway serving loop
so a frozen event loop dumps all-thread stacks and hard-exits with the
restart exit code, letting systemd/launchd/Docker relaunch the process.
Opt-in via gateway.watchdog YAML block and --watchdog/--watchdog-timeout
CLI flags; zero cost when disabled. No systemd unit change needed since it
reuses GATEWAY_RESTART_EXIT_CODE (75).

Co-authored-by: MervinPraison <[email protected]>
2026-07-26 09:53:42 +00:00
praisonai-triage-agent[bot] 3f29794da9 Merge pull request #3401 from MervinPraison/claude/issue-3400-20260726-0822
fix: harden wrapper adapters + DRY bootstrap (fixes #3400)
2026-07-26 09:32:04 +00:00
praisonai-triage-agent[bot]andMervin Praison c8bb248ee3 fix: atomic cross-process RMW + legacy JSON migration for SQLite transcript store
- Make add_message/_modify_session_locked run the whole read-modify-write
  inside a single BEGIN IMMEDIATE transaction so concurrent gateway
  processes cannot lose appends (the process-local RLock alone did not
  serialize across processes). Fixes Greptile P1 lost-update.
- Import legacy per-session JSON transcripts once when the SQLite store
  first opens beside them, so upgrading to the sqlite default preserves
  durable/resumable history. Fixes Greptile P1 legacy-invisibility.
- Wire the YAML session.store key through MultiChannelGatewayConfig.from_dict
  so store: file|sqlite is actually honoured.
- Add concurrent-writer and legacy-migration tests.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-26 09:28:25 +00:00
praisonai-triage-agent[bot]andMervin Praison c169bc73e2 fix: authoritative hard_timeout + honour external cancellation in RunOutcome
Addresses two P1 review findings on the RunOutcome terminal-outcome contract:

- Nested operation timeouts no longer misreported as run-budget hard_timeout.
  RunOutcome.from_exception no longer promotes a bare asyncio.TimeoutError to
  hard_timeout; the run-level budget is now the sole authoritative source of
  hard_timeout, enforced explicitly in _astart_with_outcome via a task+wait so
  only our own budget expiry maps to hard_timeout (inner TimeoutErrors -> failed).
- External asyncio.CancelledError is re-raised instead of being swallowed into a
  benign RunOutcome, so cooperative cancellation / host shutdown is honoured.

Updates tests accordingly and adds coverage for nested-timeout->failed and
external-cancellation-propagates.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-26 09:25:25 +00:00
praisonai-triage-agent[bot]andMervinPraison 5352aa67fb fix: add SQLite-backed transcript store for concurrent gateways (fixes #3407)
Implement SqliteTranscriptStore(DefaultSessionStore) storing session
transcripts as one row per session in a WAL SQLite DB (concurrent readers,
transactional single-row writes, indexed lookups) instead of per-session JSON
files under a cross-process FileLock. It overrides only the persistence
primitives, inheriting all retention/compaction, message API, search scoring,
bookends and lineage-dedup logic unchanged.

Directory scans (list/search/gateway routing) are replaced with indexed
SELECTs. The gateway now defaults to this store when persistence is enabled,
selectable via a new `session.store` config key (`sqlite` | `file`).

Co-authored-by: MervinPraison <[email protected]>
2026-07-26 09:20:59 +00:00
praisonai-triage-agent[bot]andMervinPraison 4ad4c85451 fix: add canonical RunOutcome terminal-outcome for agent runs (fixes #3406)
Adds a small, closed RunOutcome result type in core plus an opt-in
return_outcome=True on run()/astart() so long-running hosts (gateways/bots)
can decide delivery/retry/DLQ from one field instead of inferring the
terminal state from exception identity. Distinguishes
completed|hard_timeout|cancelled|aborted|failed. String return unchanged.

Co-authored-by: MervinPraison <[email protected]>
2026-07-26 09:19:01 +00:00
praisonai-triage-agent[bot]andMervin Praison 2a81e48638 fix: restore team conversation history for YAML session continuity
Core save/restore_session_state only persist team._state, not per-agent
chat_history, so resumed/forked YAML team runs did not actually continue
the prior conversation (Greptile P1). Add wrapper-only capture/rehydrate
helpers that stash each agent's chat_history into team state on save and
re-inject it on restore — parity with the single-agent path, no core
change and no new Agent/AgentTeam params.

Also replace the source-text arun test with a behavioral call-order test
and add roundtrip/no-duplicate coverage for the chat-history helpers.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-26 09:07:02 +00:00
praisonai-triage-agent[bot]andMervinPraison 0d6e07b2f0 fix: CLI session continuity for YAML/AgentTeam runs (fixes #3402)
Route YAML/team runs through the same --continue/--session/--fork/--no-save
continuity the single-agent prompt path uses, via existing core APIs.

- praisonai_adapter.arun(): resolve resume_session/auto_save from cli_config,
  force-enable shared memory when a session is active, restore_session_state
  before astart() and save_session_state after (save never fails a run).
- praison_ai._extract_cli_config_for_yaml(): thread resume_session/auto_save
  into cli_config for `run agents.yaml`.

Wrapper-only; no new params/deps/core changes. Adds regression tests.

Co-authored-by: MervinPraison <[email protected]>
2026-07-26 09:00:07 +00:00
praisonai-triage-agent[bot]andMervin Praison baa86920fa fix: lazy-register default readers at call time + guard bootstrap find_spec
Address final-review P1s on #3401:
- Composite readers (AutoReader/DirectoryReader/GlobReader) now idempotently
  wire the default readers into the core registry on first load(), so they no
  longer silently return [] when register_default_adapters() was never called.
  Keeps imports side-effect free (wrapper does heavy wiring at call time).
- _ensure_sibling() guards importlib.util.find_spec against ImportError/
  ValueError from a discoverable-but-broken installed sibling, falling back to
  the monorepo checkout instead of crashing.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-26 08:33:50 +00:00
praisonai-triage-agent[bot]andMervinPraison f84842ea86 fix: harden wrapper adapters + DRY bootstrap (fixes #3400)
- Remove import-time auto-registration in adapters/{retrievers,rerankers,
  readers}.py so importing them no longer mutates core-SDK singletons;
  add idempotent, thread-safe register_default_adapters() single edge
  (mirrors vector_stores.py policy).
- Make aretrieve()/arerank() genuinely async via asyncio.to_thread so the
  blocking provider call no longer freezes the caller's event loop.
- Collapse the six copy-pasted ensure_praisonai_* functions in
  _bootstrap.py into one _ensure_sibling() helper + table, fixing the
  sys.path double-insert race with a lock.

Co-authored-by: MervinPraison <[email protected]>
2026-07-26 08:26:50 +00:00
praisonai-triage-agent[bot]andMervin Praison 6ac733e74c fix: align home-boundary docstring and add regression tests
Update _load_project_config docstring to reflect that home is now
excluded from project config discovery, and add two regression tests
covering the home-directory walk-up boundary.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-26 08:20:41 +00:00
praisonai-triage-agent[bot]andMervin Praison 4b6bf44630 fix(train): local GGUF export, correct llama.cpp binary lookup, disk preflight
Address reviewer P1s on MTP fast-inference PR:
- export gguf now produces a LOCAL .gguf (needed by serve/--mtp-draft) and
  only additionally pushes to the Hub when --hf is given (was Hub-only).
- find_llama_binary no longer returns a differently-named executable when
  LLAMA_CPP_BIN points at one binary and a sibling is requested; falls through
  to PATH / raises instead of launching e.g. llama-cli with server flags.
- Ollama disk preflight only enforces the 1.5x requirement when the source
  size is known; skips (no false-positive block) for Hub-backed FROM.

Adds 6 tests (binary-lookup mismatch cases, gguf local/push dispatch,
unknown-source disk skip); full praisonai-train unit suite 118 passed.

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

Co-authored-by: Mervin Praison <[email protected]>
2026-07-26 00:42:13 +00:00
MervinPraisonandClaude Opus 4.8 8355b7ca49 feat(train): MTP fast-inference support (Gemma-4 self-speculative decoding)
Adds Multi-Token Prediction (MTP) support so a fine-tuned Gemma-4 model can be
served with lossless self-speculative decoding via llama.cpp --spec-type draft-mtp,
using the matching STOCK drafter (no drafter retraining needed).

New (additive):
- train/_mtp.py       resolve_drafter()/fetch_drafter() -> unsloth gemma-4 MTP
                      drafter GGUF (E2B/E4B/12B, verified on the Hub)
- train/_llamacpp.py  find_llama_binary/build_mtp_cmd/serve/benchmark +
                      parse_llama_timings (models _ollama.py error style)
- cli/commands/serve.py  'praisonai-train serve --gguf ... [--benchmark]',
                      auto-fetches drafter, clean fallback for non-Gemma-4
- tests/unit/train/test_mtp.py  22 tests (resolver, download, flag assembly,
                      binary-missing, timing parse)

Wiring (minimal edits):
- cli/commands/train.py  'export --mtp-draft' fetches the drafter alongside GGUF
- train/llm/trainer.py   KNOWN_KEYS += mtp_draft/mtp_draft_repo/mtp_draft_file/
                         spec_draft_n_max
- cli/app.py             register serve subcommand

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-26 01:23:55 +01:00
MervinPraison 631d2e90b0 docs: auto-update documentation parity trackers [skip ci] 2026-07-25 18:08:49 +00:00
praisonai-triage-agent[bot] 1f1df1f5d4 Merge pull request #3395 from MervinPraison/claude/issue-3393-20260725-1713
fix: remove dead code helpers in config/parse_utils.py
2026-07-25 18:08:12 +00:00
MervinPraison 316893a91e fix(release): 3-day patch cadence and explicit PyPI __token__ auth
Extend release-gate dedupe from daily to every 3 days and configure uv publish with UV_PUBLISH_USERNAME=__token__ per PyPI API token guidance.
2026-07-25 18:24:10 +01:00
MervinPraison aa0b7dcfcc Release v4.6.156 2026-07-25 17:23:45 +00:00
MervinPraison 7b01d4c5c8 Bump praisonai-sandbox to 0.0.6 2026-07-25 17:23:39 +00:00
MervinPraison bc794bd686 Bump praisonai-mcp to 0.0.8 2026-07-25 17:23:33 +00:00
MervinPraison 8c8f4285e6 Bump praisonai-browser to 0.0.8 2026-07-25 17:23:28 +00:00
MervinPraison ec4fb7cf0d Bump praisonai-train to 0.0.12 2026-07-25 17:23:22 +00:00
MervinPraison e9c2876b39 Bump praisonai-bot to 0.0.41 2026-07-25 17:23:16 +00:00
MervinPraison 4cdf68fdd5 Bump praisonai-code to 0.0.56 2026-07-25 17:23:09 +00:00
MervinPraison c7db22aee1 Bump praisonaiagents to 1.6.160 2026-07-25 17:23:01 +00:00
praisonai-triage-agent[bot]andMervinPraison 7e49f3a167 fix: remove dead code helpers in config/parse_utils.py (fixes #3393)
Remove three module-level helpers that were never referenced anywhere in
the monorepo and were not part of the public API (no __all__, absent from
config/__init__.py and the top-level lazy-import map):

- parse_url_to_config
- is_numeric_string
- make_array_error

All exported/used helpers remain untouched.

Co-authored-by: MervinPraison <[email protected]>
2026-07-25 17:16:10 +00:00
praisonai-triage-agent[bot] 14726713db Merge pull request #3390 from MervinPraison/claude/issue-3389-20260725-1616
perf: lazy-load pathlib in praisonai._bootstrap
2026-07-25 17:14:20 +00:00
Mervin Praison 3d2170c817 Merge pull request #3391 from Hore01/fix-ui-default-app-utf8
fix: read bundled default_app.py using UTF-8
2026-07-25 18:07:47 +01:00
praisonai-triage-agent[bot]andMervinPraison fbf6bc7c20 perf: lazy-load pathlib in _bootstrap to trim import hot path (fixes #3389)
Move the module-level `from pathlib import Path` into each
`ensure_praisonai_*` monorepo-dev fallback branch. Path is only ever
referenced after the `import praisonai_<pkg>` early-return fails, so the
installed-wheel hot path no longer pays pathlib's ~8.7ms cold-import cost.
Behaviour is byte-for-byte identical.

Co-authored-by: MervinPraison <[email protected]>
2026-07-25 16:18:23 +00:00
praisonai-triage-agent[bot]andMervin Praison 77cbae75b7 fix: honor read-abort in hierarchical store + scope forced approval per-call
- session/hierarchy.py: mirror base loader contract so a transient OSError on
  an existing file re-raises (instead of swallowing IOError and returning an
  empty session), letting _modify_session_locked abort the write and preserve
  history. Malformed JSON still starts fresh.
- approval/registry.py + agent/tool_execution.py: add per-call `force` to
  approve_sync/approve_async so a PermissionManager `ask` rule gates only the
  current call without mutating shared registry state, fixing the leak where an
  unnamed agent's rule registered globally and gated other agents.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-25 07:32:00 +00:00
praisonai-triage-agent[bot]andMervinPraison 636e7fe169 fix: async-safe handoff chain, session read-error data safety, per-agent approval scoping (fixes #3368)
Gap 1: replace threading.local() handoff-chain storage with contextvars.ContextVar so concurrent asyncio handoffs no longer share one chain and corrupt each other's cycle/depth checks.

Gap 2: distinguish a transient OS read error from no-file/corrupt-JSON in the session store so a momentary read failure aborts the write (returns False) instead of silently overwriting real history with an empty session.

Gap 3: scope ApprovalRegistry tool-requirement state per agent so a per-agent PermissionManager ask rule no longer leaks an approval gate onto unrelated agents in the same process. Global registration (DEFAULT_DANGEROUS_TOOLS) is unaffected.

Co-authored-by: MervinPraison <[email protected]>
2026-07-25 07:22:43 +00:00
praisonai-triage-agent[bot]andMervin Praison 83672e1bf0 fix(train): reviewer fixes — cached HF login, CPU-only validation, OLLAMA_HOST-aware readiness, clean ollama-create errors
- Accept cached `huggingface-cli login` (get_token) in preflight, not just HF_TOKEN env (Greptile P1)
- Gate the hard CUDA check on train enabled so publish/export-only (train: false) validates on CPU (CodeRabbit Major)
- Resolve Ollama readiness endpoint from OLLAMA_HOST instead of hardcoded 127.0.0.1:11434 (Greptile P1)
- Translate `ollama create` failure into a clean RuntimeError and catch CalledProcessError in main()/export (CodeRabbit)
- Close serve_err TemporaryFile deterministically (CodeRabbit)
- Fix "Free up free space" typo (CodeRabbit)
- Guard non-mapping YAML config and require --model-dir to be a directory in export (CodeRabbit)
- Validate quantization_method in for_export too (CodeRabbit)
- Add tests for cached-login, train:false CPU, OLLAMA_HOST, and ollama-create failure

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

Co-authored-by: Mervin Praison <[email protected]>
2026-07-25 07:19:57 +00:00
MervinPraisonandClaude Opus 4.8 095b004bfb feat(train): non-developer robustness — clean errors, preflight, export command, Ollama/GGUF/HF failure handling
Make praisonai-train usable by a non-developer: replace raw tracebacks with
clean actionable errors, validate the config up front, and harden the
Ollama/GGUF/HF export paths against the exact failures hit in practice.

trainer.py:
- main() wraps construction + run(); ValueError/RuntimeError print as a single
  "ERROR: <msg>" line and exit 1 (no traceback); KeyboardInterrupt exits cleanly.
- validate_config() preflight (fails fast BEFORE model/GPU load): no-CUDA GPU,
  missing HF_TOKEN when publishing, <10GB free disk, invalid quantization_method.
- check_gpu() guarded so it no longer crashes raw on a CPU-only box.
- Unknown-key warning now collects all keys and suggests the closest known key
  (difflib) in one clear block.
- Silent-behavior NOTES: num_samples head-N-before-shuffle, split_type
  validation/test contamination into training, and the max_steps=2800 default.
- HF push (merged/gguf) translates HfHubHTTPError 401/403 into actionable
  messages; rmtree guarded so a namespaced repo id ("user/model") is never
  treated as a local path to delete.
- Template fixes: warn when no known chat template matches, drop the broken empty
  DeepSeek stop tokens, and never emit an empty PARAMETER stop line.
- for_export() classmethod to build an export-only trainer (no dataset needed).

_ollama.py:
- create_and_push_ollama_model() accepts optional quantization (--quantize),
  disk pre-check on the OLLAMA_MODELS volume, and translates push 401/403 into a
  message pointing at ~/.ollama/id_ed25519.pub + ollama.com/settings/keys.
- ensure_ollama_running() waits 15s, probes GET /api/version, and surfaces serve
  stderr in the timeout message.

cli/commands/train.py:
- New `export <ollama|gguf|hf>` command to publish an already-trained model
  without re-running training.

tests: tests/unit/train/test_robustness.py (14 tests, all deps stubbed).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-25 08:08:28 +01:00
praisonai-triage-agent[bot]andMervinPraison 2bc80d84b7 refactor: extract duplicate MCP to_openai_tool() into shared helper (fixes #3364)
Add build_openai_tool_dict to mcp_schema_utils.py and delegate from the
three transport tool classes (HTTPStreamMCPTool, SSEMCPTool,
WebSocketMCPTool). Output dicts, including the __praisonai_deferrable__
marker, are unchanged.

Co-authored-by: MervinPraison <[email protected]>
2026-07-24 17:16:12 +00:00
praisonai-triage-agent[bot]andMervinPraison c17327f61e fix: reuse canonical token heuristic in compaction fallback (fixes #3363)
Replace flat len(text)//4 offline fallback in ContextCompactor.estimate_tokens
with the canonical estimate_tokens_heuristic from context.tokens, mirroring
context/aggregator.py. This removes duplicate logic and fixes under-counting
of non-ASCII (CJK/dense-script) text on the offline path.

Co-authored-by: MervinPraison <[email protected]>
2026-07-24 17:15:09 +00:00
praisonai-triage-agent[bot]andMervinPraison 285894d1a4 fix: root /undo at the bot workspace, not process cwd (fixes #3355)
Bot/gateway file tools resolve against a per-session Workspace attached to
the agent after construction, but the FileSnapshot backing Agent.undo was
created rooted at os.getcwd() — so /undo tracked the wrong directory.

Add Agent.set_snapshot_root() (core, parameter-only) and call it from the
bot smart-defaults after attaching the workspace so change tracking follows
the tools. Deliberately minimal: the per-turn workspace swap (bug 3) and
policy worktrees (blocked on #3354's WorktreeService) are out of scope here.

Co-authored-by: MervinPraison <[email protected]>
2026-07-24 14:27:07 +00:00
praisonai-triage-agent[bot]andMervin Praison 819450ec07 test(gateway): assert deep=False in status call after adding --deep flag
The gateway status command now passes the additive deep flag to
handler.status(); update the assertion to match the new backward-
compatible default.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-24 10:36:06 +00:00
praisonai-triage-agent[bot]andMervin Praison f805090499 fix(gateway): stop leaking bearer token over plaintext HTTP, honour hook redaction, avoid first-run inbound false-fail
- Only attach GATEWAY_AUTH_TOKEN over loopback or HTTPS; never over remote
  plaintext HTTP in preflight probes and version-skew check
- Slack @mention: use hook-returned content verbatim so an intentionally
  emptied/redacted message is not silently restored to raw event text
- Inbound metrics: track whether a baseline pre-existed so the first check
  against pre-existing traffic reports "baseline established" instead of a
  false "no inbound"

Co-authored-by: Mervin Praison <[email protected]>
2026-07-24 10:36:06 +00:00
MervinPraison e9a20f0686 feat(gateway): add tiered diagnostics for runtime, inbound, and duplicates
Extend gateway test/status with --check-runtime, --check-inbound, and
--check-duplicates; add sessions list/show, enriched /health, metrics
delta, doctor deep checks, and Slack @mention liveness fixes so operators
can prove live delivery and detect competing gateways.
2026-07-24 10:36:06 +00:00
Dhivya-Bharathy 1cfb2bc26f fix: resolve 4 remaining E2E example failures after batch-3 merge 2026-07-24 14:25:40 +05:30
praisonai-triage-agent[bot]andMervin Praison eacd9df36f fix(skills): query MCP server registry live instead of caching stale snapshot
Addresses greptile P1: CapabilityValidator cached the first _get_available_servers()
snapshot, so a skill validated before its MCP server registered via with_tool_prefix()
stayed permanently UNAVAILABLE under STRICT even after the server connected. The MCP
registry read is a cheap set copy, so query it live and drop the dead _server_cache
field (issue #3307).

Co-authored-by: Mervin Praison <[email protected]>
2026-07-23 10:45:56 +00:00
praisonai-triage-agent[bot]andMervin Praison 7db836da1e fix: aworkflow loop expansion, concurrent turn-tool race, MCP skill-gate discovery (fixes #3307)
Gap 1: Port sync workflow()'s loop-task pre-expansion into aworkflow() so
async CSV-driven loop start tasks run per-row instead of once.

Gap 2: Guard the per-turn tool buffer (_turn_tools_used) with a DualLock via
_reset_turn_tools/_record_turn_tool/_drain_turn_tools helpers, matching the
existing chat_history protection, so concurrent chat()/achat() turns on one
Agent no longer corrupt hook/self-improvement data.

Gap 3: Track namespaced MCP server names in a process-level registry and let
the skills CapabilityValidator discover them, so MCP-server-gated skills can
pass STRICT validation instead of always failing closed.

Co-authored-by: Mervin Praison <[email protected]>
2026-07-23 10:27:43 +00:00
276 changed files with 15860 additions and 2013 deletions

No files matched your search

+28 -4
View File
@@ -36,8 +36,10 @@ assert.strictEqual(dayStart.toISOString(), '2026-07-08T00:00:00.000Z');
},
},
};
assert.strictEqual(rg.PATCH_RELEASE_INTERVAL_DAYS, 3);
assert.strictEqual(
await rg.hasSuccessfulReleaseToday(mockGithub, 'o', 'r', noonUtc),
await rg.hasSuccessfulReleaseWithinDays(mockGithub, 'o', 'r', noonUtc),
true
);
@@ -46,12 +48,34 @@ assert.strictEqual(dayStart.toISOString(), '2026-07-08T00:00:00.000Z');
{ headSha: 'abc', isCiTrigger: false, bump: 'patch', now: noonUtc },
null
);
assert.ok(result.reasons.some((r) => r.includes('already released today')));
assert.ok(result.reasons.some((r) => r.includes('every 3 days')));
const oldReleaseGithub = {
rest: {
actions: {
listWorkflowRuns: async () => ({
data: {
workflow_runs: [
{
conclusion: 'success',
created_at: '2026-07-04T09:00:00Z',
status: 'completed',
},
],
},
}),
},
},
};
assert.strictEqual(
await rg.hasSuccessfulReleaseWithinDays(oldReleaseGithub, 'o', 'r', noonUtc),
false
);
console.log('ok: bumpPatch');
console.log('ok: readVersionsFromTree');
console.log('ok: pypiVersionExists missing version');
console.log('ok: utcDayStart');
console.log('ok: hasSuccessfulReleaseToday');
console.log('ok: daily dedupe blocks second release');
console.log('ok: hasSuccessfulReleaseWithinDays');
console.log('ok: 3-day dedupe blocks second release');
})();
+28 -6
View File
@@ -5,6 +5,8 @@
const https = require('https');
const PACKAGE_PATHS = ['src/praisonai', 'src/praisonai-agents', 'src/praisonai-code'];
/** Minimum days between successful patch auto-releases. */
const PATCH_RELEASE_INTERVAL_DAYS = 3;
const ACTIVE_RELEASE_STATUSES = new Set([
'queued', 'in_progress', 'waiting', 'pending', 'requested',
]);
@@ -79,8 +81,18 @@ function utcDayStart(now = new Date()) {
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
}
async function hasSuccessfulReleaseToday(github, owner, repo, now = new Date()) {
const dayStart = utcDayStart(now);
function releaseIntervalStart(now = new Date(), intervalDays = PATCH_RELEASE_INTERVAL_DAYS) {
return new Date(now.getTime() - intervalDays * 24 * 60 * 60 * 1000);
}
async function hasSuccessfulReleaseWithinDays(
github,
owner,
repo,
now = new Date(),
intervalDays = PATCH_RELEASE_INTERVAL_DAYS,
) {
const windowStart = releaseIntervalStart(now, intervalDays);
const runs = await github.rest.actions.listWorkflowRuns({
owner,
repo,
@@ -89,10 +101,15 @@ async function hasSuccessfulReleaseToday(github, owner, repo, now = new Date())
per_page: 30,
});
return runs.data.workflow_runs.some(
(r) => r.conclusion === 'success' && new Date(r.created_at) >= dayStart
(r) => r.conclusion === 'success' && new Date(r.created_at) >= windowStart
);
}
/** @deprecated Use hasSuccessfulReleaseWithinDays — kept for selftests. */
async function hasSuccessfulReleaseToday(github, owner, repo, now = new Date()) {
return hasSuccessfulReleaseWithinDays(github, owner, repo, now, 1);
}
async function lastGreenCoreTestsSha(github, owner, repo) {
const runs = await github.rest.actions.listWorkflowRuns({
owner,
@@ -135,9 +152,11 @@ async function evaluateReleasePreflight(github, owner, repo, options, core) {
}
const referenceTime = options.now instanceof Date ? options.now : new Date();
if (await hasSuccessfulReleaseToday(github, owner, repo, referenceTime)) {
const day = referenceTime.toISOString().slice(0, 10);
reasons.push(`already released today (UTC ${day}); max one patch release per day`);
if (await hasSuccessfulReleaseWithinDays(github, owner, repo, referenceTime)) {
reasons.push(
`already released within last ${PATCH_RELEASE_INTERVAL_DAYS} days; `
+ `max one patch release every ${PATCH_RELEASE_INTERVAL_DAYS} days`
);
return out;
}
@@ -222,6 +241,9 @@ module.exports = {
bumpPatch,
readVersionsFromTree,
pypiVersionExists,
PATCH_RELEASE_INTERVAL_DAYS,
releaseIntervalStart,
hasSuccessfulReleaseWithinDays,
hasSuccessfulReleaseToday,
utcDayStart,
evaluateReleasePreflight,
+3 -3
View File
@@ -1,12 +1,12 @@
name: Nightly Release Gate
# Preflight before PyPI Release (patch bump).
# Triggers: Core Tests success on main (workflow_run) or nightly cron at 00:00 UTC.
# Dedupe: max one successful patch release per UTC day (see release-gate.js).
# Triggers: Core Tests success on main (workflow_run) or cron every 3 days at 00:00 UTC.
# Dedupe: max one successful patch release every 3 days (see release-gate.js).
on:
schedule:
- cron: '0 0 * * *'
- cron: '0 0 */3 * *'
workflow_dispatch:
inputs:
dry_run:
+3 -1
View File
@@ -134,7 +134,9 @@ jobs:
'pypi-auto' || 'pypi'
}}
env:
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN || secrets.PYPI_API_TOKEN }}
# PyPI API token auth: username __token__, password = pypi-… token (see pypi.org/help/#invalid-auth)
UV_PUBLISH_USERNAME: __token__
UV_PUBLISH_PASSWORD: ${{ secrets.PYPI_TOKEN || secrets.PYPI_API_TOKEN }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
steps:
- name: Checkout main
+7 -1
View File
@@ -83,6 +83,7 @@ Methods:
* <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, goal: Optional[str] = None, goal_criteria: Optional[Any] = None, judge_model: Optional[str] = None) -> '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">set_snapshot_root</a>(project_path: str) -> bool</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', action: str = 'add', **kwargs: Any) -> None</code>
* <code title="class Agent">Agent.<a href="./src/praisonai-agents/praisonaiagents/agent/agent.py">stream_emitter</a>() -> Optional[Any]</code>
@@ -568,6 +569,7 @@ Methods:
* <code title="class MCP">MCP.<a href="./src/praisonai-agents/praisonaiagents/mcp/mcp.py">get_prompts</a>() -> List[dict]</code>
* <code title="class MCP">MCP.<a href="./src/praisonai-agents/praisonaiagents/mcp/mcp.py">get_resources</a>() -> List[dict]</code>
* <code title="class MCP">MCP.<a href="./src/praisonai-agents/praisonaiagents/mcp/mcp.py">get_tools</a>() -> List[Callable]</code>
* <code title="class MCP">MCP.<a href="./src/praisonai-agents/praisonaiagents/mcp/mcp.py">list_active_server_names</a>() -> set</code>
* <code title="class MCP">MCP.<a href="./src/praisonai-agents/praisonaiagents/mcp/mcp.py">shutdown</a>()</code>
* <code title="class MCP">MCP.<a href="./src/praisonai-agents/praisonaiagents/mcp/mcp.py">to_openai_tool</a>()</code>
* <code title="class MCP">MCP.<a href="./src/praisonai-agents/praisonaiagents/mcp/mcp.py">with_tool_prefix</a>(prefix: str) -> 'MCP'</code>
@@ -731,7 +733,7 @@ Methods:
Types:
```python
from praisonaiagents import AgentAppConfig, AgentAppProtocol, AgentFlow, AgentManager, AgentOSConfig, AgentOSProtocol, AgentTeam, AutoApproveBackend, EmbeddingResult, RetryBackoffConfig, __version__, aembedding, aembeddings, embedding, embeddings, get_dimensions
from praisonaiagents import AgentAppConfig, AgentAppProtocol, AgentFlow, AgentManager, AgentOSConfig, AgentOSProtocol, AgentTeam, AutoApproveBackend, EmbeddingResult, RetryBackoffConfig, RunOutcome, __version__, aembedding, aembeddings, embedding, embeddings, get_dimensions
```
Methods:
@@ -799,12 +801,16 @@ Methods:
* <code title="class AgentTeam">AgentTeam.<a href="./src/praisonai-agents/praisonaiagents/agents/agents.py">set_state</a>(key: str, value: Any) -> None</code>
* <code title="class AgentTeam">AgentTeam.<a href="./src/praisonai-agents/praisonaiagents/agents/agents.py">spawn_sub_agent</a>(agent: Agent, task: Any, completion_callback: Optional[Callable[[SubAgentCompletionEvent], Any]] = None, metadata: Optional[Dict[str, Any]] = None) -> SpawnedSubAgent</code>
* <code title="class AgentTeam">AgentTeam.<a href="./src/praisonai-agents/praisonaiagents/agents/agents.py">start</a>(content = None, return_dict = False, output = None, **kwargs)</code>
* <code title="class AgentTeam">AgentTeam.<a href="./src/praisonai-agents/praisonaiagents/agents/agents.py">stream_emitter</a>()</code>
* <code title="class AgentTeam">AgentTeam.<a href="./src/praisonai-agents/praisonaiagents/agents/agents.py">todo_list</a>()</code>
* <code title="class AgentTeam">AgentTeam.<a href="./src/praisonai-agents/praisonaiagents/agents/agents.py">update_plan_step_status</a>(step_id: str, status: str) -> bool</code>
* <code title="class AgentTeam">AgentTeam.<a href="./src/praisonai-agents/praisonaiagents/agents/agents.py">update_state</a>(updates: Dict) -> None</code>
* <code title="class AgentTeam">AgentTeam.<a href="./src/praisonai-agents/praisonaiagents/agents/agents.py">wait_for_completions</a>(timeout: Optional[float] = None, agent_ids: Optional[List[str]] = None) -> List[SubAgentCompletionEvent]</code>
* <code title="class AutoApproveBackend">AutoApproveBackend.<a href="./src/praisonai-agents/praisonaiagents/approval/backends.py">request_approval</a>(request: ApprovalRequest) -> ApprovalDecision</code>
* <code title="class AutoApproveBackend">AutoApproveBackend.<a href="./src/praisonai-agents/praisonaiagents/approval/backends.py">request_approval_sync</a>(request: ApprovalRequest) -> ApprovalDecision</code>
* <code title="class RunOutcome">RunOutcome.<a href="./src/praisonai-agents/praisonaiagents/agent/run_outcome.py">completed</a>(output: Optional[str] = None) -> 'RunOutcome'</code>
* <code title="class RunOutcome">RunOutcome.<a href="./src/praisonai-agents/praisonaiagents/agent/run_outcome.py">from_exception</a>(exc: BaseException, output: Optional[str] = None) -> 'RunOutcome'</code>
* <code title="class RunOutcome">RunOutcome.<a href="./src/praisonai-agents/praisonaiagents/agent/run_outcome.py">succeeded</a>() -> bool</code>
* <code title="function">praisonaiagents.<a href="./src/praisonai-agents/praisonaiagents/embedding/embed.py">aembedding</a>(input: Union[str, List[str]], model: str = 'text-embedding-3-small', dimensions: Optional[int] = None, encoding_format: str = 'float', timeout: float = 600.0, api_key: Optional[str] = None, api_base: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs) -> EmbeddingResult</code>
* <code title="function">praisonaiagents.<a href="./src/praisonai-agents/praisonaiagents/embedding/embed.py">aembeddings</a>(input: Union[str, List[str]], model: str = 'text-embedding-3-small', dimensions: Optional[int] = None, encoding_format: str = 'float', timeout: float = 600.0, api_key: Optional[str] = None, api_base: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None, **kwargs) -> EmbeddingResult</code>
* <code title="function">praisonaiagents.<a href="./src/praisonai-agents/praisonaiagents/embedding/dimensions.py">get_dimensions</a>(model_name: str) -> int</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.6.155" \
"praisonai>=4.6.157" \
"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.6.155" \
"praisonai>=4.6.157" \
"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.6.155" \
"praisonai>=4.6.157" \
"praisonai[ui]" \
"praisonai[crewai]"
+11 -1
View File
@@ -1,5 +1,15 @@
import threading
import time
from praisonaiagents import Agent
if __name__ == "__main__":
agent = Agent(name="TweetAgent", instructions="Create a Tweet based on the topic provided")
agent.launch(port=8080, protocol="mcp", path="/mcp")
server = threading.Thread(
target=lambda: agent.launch(port=8080, protocol="mcp", path="/mcp"),
daemon=True,
)
server.start()
time.sleep(2)
print("MCP server started on http://127.0.0.1:8080/mcp")
@@ -150,7 +150,7 @@ def main():
agent = Agent(
name="AI Research Assistant",
instructions="You are an AI research assistant. Use your knowledge base to answer questions about artificial intelligence topics.",
knowledge={**rerank_config, "sources": sample_documents},
knowledge={"sources": sample_documents, "rerank": True},
llm="gpt-4o-mini"
)
@@ -67,6 +67,7 @@ agents_system = AgentTeam(
print("Starting graph memory demonstration...")
result = agents_system.start()
print(f"\nGraph Memory Result: {result[:200]}...")
result_text = str(result) if result is not None else ""
print(f"\nGraph Memory Result: {result_text[:200]}...")
print("\n✅ Graph memory integration complete!")
print("Agent built knowledge graph and performed relationship-aware queries.")
+18 -18
View File
@@ -14,18 +14,18 @@ def test_imports():
"""Test that all required modules can be imported."""
try:
from praisonaiagents import Agent
print("✅ Agent imported successfully")
print("[OK] Agent imported successfully")
from praisonaiagents.tools import execute_command
print("✅ execute_command tool imported successfully")
print("[OK] execute_command tool imported successfully")
from praisonaiagents.approval import get_approval_registry, AutoApproveBackend
print("✅ Approval system imported successfully")
print("[OK] Approval system imported successfully")
return True
except ImportError as e:
print(f"❌ Import failed: {e}")
print(f"[FAIL] Import failed: {ascii(e)}")
return False
def test_agent_creation():
@@ -40,11 +40,11 @@ def test_agent_creation():
)
assert agent.name == 'test-agent'
print("✅ Agent creation successful")
print("[OK] Agent creation successful")
return True
except Exception as e:
print(f"❌ Agent creation failed: {e}")
print(f"[FAIL] Agent creation failed: {ascii(e)}")
return False
def test_approval_system():
@@ -55,11 +55,11 @@ def test_approval_system():
registry = get_approval_registry()
registry.set_backend(AutoApproveBackend())
print("✅ Approval system configuration successful")
print("[OK] Approval system configuration successful")
return True
except Exception as e:
print(f"❌ Approval system test failed: {e}")
print(f"[FAIL] Approval system test failed: {ascii(e)}")
return False
def test_external_agent_import():
@@ -80,11 +80,11 @@ def test_external_agent_import():
# Now try to import our agent
import praisonai_external_agent
print("✅ External agent import successful")
print("[OK] External agent import successful")
return True
except Exception as e:
print(f"❌ External agent import failed: {e}")
print(f"[FAIL] External agent import failed: {ascii(e)}")
return False
def test_multi_agent_import():
@@ -104,11 +104,11 @@ def test_multi_agent_import():
sys.modules['harbor.models.agent.context'] = MagicMock()
import multi_agent_example
print("✅ Multi-agent example import successful")
print("[OK] Multi-agent example import successful")
return True
except Exception as e:
print(f"❌ Multi-agent example import failed: {e}")
print(f"[FAIL] Multi-agent example import failed: {ascii(e)}")
return False
def test_wrapper_agent_import():
@@ -128,11 +128,11 @@ def test_wrapper_agent_import():
sys.modules['harbor.models.agent.context'] = MagicMock()
import praisonai_wrapper_agent
print("✅ Wrapper agent import successful (CLI-based approach)")
print("[OK] Wrapper agent import successful (CLI-based approach)")
return True
except Exception as e:
print(f"❌ Wrapper agent import failed: {e}")
print(f"[FAIL] Wrapper agent import failed: {ascii(e)}")
return False
if __name__ == "__main__":
@@ -152,19 +152,19 @@ if __name__ == "__main__":
total = len(tests)
for test_name, test_func in tests:
print(f"\n🧪 Testing {test_name}...")
print(f"\n[TEST] {test_name}...")
try:
if test_func():
passed += 1
except Exception as e:
print(f"❌ Test {test_name} crashed: {e}")
print(f"[FAIL] Test {test_name} crashed: {ascii(e)}")
print("\n" + "=" * 55)
print(f"Results: {passed}/{total} tests passed")
if passed == total:
print("🎉 ALL BASIC TESTS PASSED!")
print("[OK] ALL BASIC TESTS PASSED!")
print("The Terminal-Bench integration components are properly structured.")
else:
print("❌ Some tests failed - check output above")
print("[FAIL] Some tests failed - check output above")
sys.exit(1)
+4 -2
View File
@@ -30,9 +30,11 @@ def main():
else:
print(f"Found {len(stories)} top stories:")
for story in stories:
print(f" - {story.get('title', 'N/A')[:50]}...")
title = story.get("title") or "N/A"
url = story.get("url") or "N/A"
print(f" - {title[:50]}...")
print(f" Score: {story.get('score', 'N/A')} | Comments: {story.get('descendants', 'N/A')}")
print(f" URL: {story.get('url', 'N/A')[:60]}...")
print(f" URL: {url[:60]}...")
print()
print("✅ Hacker News tool working correctly!")
+17 -17
View File
@@ -18,39 +18,39 @@ This report compares **Python SDK feature categories** against **Python document
| Category | Features | Docs | Lines |
|----------|----------|------|-------|
| ✅ AGUI | 1 | 2 | 420 |
| ✅ Agent | 21 | 46 | 14657 |
| ✅ Agent | 21 | 46 | 14663 |
| ✅ Agent-to-Agent (A2A) | 1 | 7 | 2965 |
| ✅ Agent-to-User (A2U) | 1 | 3 | 585 |
| ✅ Approval | 1 | 5 | 2312 |
| ✅ Audio | 2 | 12 | 1000 |
| ✅ Auto Generation | 5 | 10 | 2880 |
| ✅ Autonomy | 3 | 7 | 2707 |
| ✅ Bots | 7 | 29 | 11795 |
| ✅ Bots | 7 | 31 | 12353 |
| ✅ Budget | 1 | 1 | 287 |
| ✅ CLI | 5 | 119 | 34087 |
| ✅ CLI | 5 | 119 | 34537 |
| ✅ Chunking | 2 | 2 | 385 |
| ✅ Citations | 2 | 1 | 202 |
| ✅ Code Execution | 2 | 13 | 4031 |
| ✅ Conditions | 1 | 3 | 1179 |
| ✅ Configuration | 3 | 7 | 2772 |
| ✅ Context Management | 16 | 34 | 13204 |
| ✅ Configuration | 3 | 7 | 2773 |
| ✅ Context Management | 16 | 34 | 13206 |
| ✅ Deep Research | 8 | 2 | 587 |
| ✅ Display | 6 | 3 | 741 |
| ✅ Embeddings | 6 | 23 | 2049 |
| ✅ Evaluation | 1 | 7 | 2905 |
| ✅ Events | 1 | 2 | 749 |
| ✅ Execution | 3 | 4 | 1528 |
| ✅ Execution | 3 | 4 | 1560 |
| ✅ Failover | 2 | 1 | 400 |
| ✅ Files | 2 | 6 | 1964 |
| ✅ Files | 2 | 6 | 2066 |
| ✅ Flow | 1 | 3 | 777 |
| ✅ Gateway | 7 | 56 | 20195 |
| ✅ Gateway | 7 | 59 | 21584 |
| ✅ Guardrails | 4 | 4 | 1673 |
| ✅ Handoffs | 11 | 6 | 2454 |
| ✅ Hooks | 2 | 9 | 4128 |
| ✅ Image | 1 | 11 | 1255 |
| ✅ Knowledge | 4 | 13 | 4160 |
| ✅ LLM | 3 | 14 | 4864 |
| ✅ Loops | 4 | 4 | 1202 |
| ✅ Loops | 4 | 5 | 1422 |
| ✅ MCP | 1 | 58 | 13322 |
| ✅ Memory | 6 | 17 | 6635 |
| ✅ OCR | 2 | 1 | 237 |
@@ -60,7 +60,7 @@ This report compares **Python SDK feature categories** against **Python document
| ✅ Parallel Execution | 3 | 2 | 497 |
| ✅ Planning | 6 | 6 | 1545 |
| ✅ Plugins | 8 | 3 | 1900 |
| ✅ Prompts | 2 | 9 | 1913 |
| ✅ Prompts | 2 | 9 | 1965 |
| ✅ Providers | 1 | 55 | 7502 |
| ✅ Query | 1 | 2 | 736 |
| ✅ RAG | 5 | 15 | 2936 |
@@ -68,14 +68,14 @@ This report compares **Python SDK feature categories** against **Python document
| ✅ Reflection | 3 | 3 | 680 |
| ✅ Retrieval | 2 | 5 | 1044 |
| ✅ Routing | 1 | 2 | 430 |
| ✅ Sandbox | 5 | 6 | 2700 |
| ✅ Sandbox | 5 | 6 | 2766 |
| ✅ Security | 1 | 3 | 2970 |
| ✅ Sessions | 4 | 13 | 5286 |
| ✅ Skills | 6 | 13 | 4946 |
| ✅ Tasks | 2 | 6 | 2743 |
| ✅ Sessions | 4 | 13 | 5302 |
| ✅ Skills | 6 | 13 | 4998 |
| ✅ Tasks | 2 | 6 | 2809 |
| ✅ Telemetry | 1 | 2 | 604 |
| ✅ Templates | 1 | 8 | 1657 |
| ✅ Tools | 12 | 133 | 37934 |
| ✅ Templates | 1 | 8 | 1663 |
| ✅ Tools | 12 | 133 | 38149 |
| ✅ Tracing | 3 | 2 | 139 |
| ✅ Vector Store | 1 | 12 | 1193 |
| ✅ Video | 2 | 6 | 649 |
@@ -87,7 +87,7 @@ This report compares **Python SDK feature categories** against **Python document
These docs exist but don't match any implemented feature category:
- ℹ️ Database (40 docs, 6184 lines)
- ℹ️ Database (41 docs, 6478 lines)
- ℹ️ Documents (1 docs, 787 lines)
---
@@ -258,6 +258,7 @@ _LAZY_IMPORTS = {
# Agent classes
'Agent': ('praisonaiagents.agent.agent', 'Agent'),
'RunOutcome': ('praisonaiagents.agent.run_outcome', 'RunOutcome'),
'RetryBackoffConfig': ('praisonaiagents.agent.retry_utils', 'RetryBackoffConfig'),
'BudgetExceededError': ('praisonaiagents.errors', 'BudgetExceededError'),
@@ -838,6 +839,7 @@ __all__ = [
# Core classes - the essentials
'Agent',
'RunOutcome',
'RetryBackoffConfig',
'AgentTeam', # Primary class for multi-agent coordination (v1.0+)
'AgentManager', # Silent alias for AgentTeam
@@ -4,7 +4,6 @@ This module consolidates all logging configuration in one place to avoid duplica
"""
import os
import json
import logging
from typing import Any, Dict, List, Optional, Union
@@ -196,6 +195,9 @@ class StructuredFormatter(logging.Formatter):
extra = {k: v for k, v in record.extra_data.items() if k not in self._STANDARD_FIELDS}
log_data.update(extra)
# Deferred: json is only needed for opt-in structured logging
import json
return json.dumps(log_data)
@@ -37,6 +37,15 @@ def __getattr__(name):
from .interrupt import InterruptController
_lazy_cache[name] = InterruptController
return InterruptController
if name in ('RunOutcome', 'TerminalReason'):
from . import run_outcome as _run_outcome_module
value = getattr(_run_outcome_module, name)
_lazy_cache[name] = value
return value
if name == 'prompt_prefix_signature':
from .prompt_cache import prompt_prefix_signature
_lazy_cache[name] = prompt_prefix_signature
return prompt_prefix_signature
# Specialized agents - lazy loaded (import rich)
if name == 'ImageAgent':
@@ -215,6 +224,9 @@ __all__ = [
'Heartbeat',
'HeartbeatConfig',
'InterruptController',
'RunOutcome',
'TerminalReason',
'prompt_prefix_signature',
'ImageAgent',
'VideoAgent',
'VideoConfig',
@@ -20,7 +20,7 @@ from .async_memory_mixin import AsyncMemoryMixin
from .tool_execution import ToolExecutionMixin, BackoffPolicy
from .chat_handler import ChatHandlerMixin
from .session_manager import SessionManagerMixin
from .async_safety import AsyncSafeState
from .async_safety import AsyncSafeState, DualLock
# NOTE: UnifiedExecutionMixin is deprecated and unused by any production path
# (Issue #2644). It is kept in the MRO for backward compatibility during the
# deprecation cycle and will be removed afterwards.
@@ -2230,7 +2230,10 @@ Your Goal: {self.goal}
# Per-turn tool-name buffer feeding the self-improve review policy.
# Populated in _execute_tool_with_context, reset each chat turn, and
# read by _trigger_after_agent_hook when tools_used is not passed.
# Guarded by a DualLock (like chat_history) so concurrent chat()/achat()
# turns on the same Agent instance don't corrupt each other's buffer.
self._turn_tools_used = []
self._turn_tools_lock = DualLock()
# Database persistence (lazy - no imports until used)
self._db = db
@@ -3198,7 +3201,44 @@ Summary:"""
# ================================================================
# Filesystem tracking convenience methods (powered by FileSnapshot)
# ================================================================
def set_snapshot_root(self, project_path: str) -> bool:
"""Root filesystem change-tracking at ``project_path``.
Bots/gateway resolve file tools against a per-chat ``Workspace`` and
attach it *after* construction, but the FileSnapshot backing
:meth:`undo`/:meth:`redo`/:meth:`diff` was created at ``__init__`` time
rooted at ``os.getcwd()``. Without this, ``/undo`` tracks the wrong
directory (never where the tools actually wrote). Call this once after
the workspace is known so change tracking follows the tools.
Rooting at a new directory clears the undo/redo stacks (they belong to
the previous root). A no-op when the root is unchanged. Returns ``True``
when a snapshot manager is rooted at ``project_path``.
"""
import os
new_root = os.path.abspath(str(project_path))
current = self._file_snapshot
if current is not None and getattr(current, "project_path", None) == new_root:
return True
try:
from ..snapshot import FileSnapshot
snapshot_dir = None
cfg = getattr(self, "autonomy_config", None)
if isinstance(cfg, dict):
snapshot_dir = cfg.get("snapshot_dir")
self._file_snapshot = FileSnapshot(
project_path=new_root,
snapshot_dir=snapshot_dir,
)
with self._snapshot_lock:
self._snapshot_stack = []
self._redo_stack = []
return True
except Exception as e: # pragma: no cover - git may be unavailable
logger.debug(f"Re-rooting FileSnapshot failed: {e}")
return False
def undo(self) -> bool:
"""Undo the last set of file changes.
@@ -7,7 +7,6 @@ async capabilities following the AsyncMemoryProtocol.
"""
import asyncio
import logging
from typing import List, Dict, Any, Optional, Union
from praisonaiagents._logging import get_logger
from ..memory.protocols import AsyncMemoryProtocol
@@ -34,7 +34,6 @@ Usage:
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 = get_logger(__name__)
@@ -2462,8 +2462,7 @@ Your Goal: {self.goal}"""
"""Internal chat implementation (extracted for trace wrapping)."""
# Reset the per-turn tool buffer so the self-improve review policy only
# sees tools used in this turn (not during a nested skill-review turn).
if not getattr(self, "_in_skill_review", False):
self._turn_tools_used = []
self._reset_turn_tools()
# Apply rate limiter if configured (before any LLM call)
if self._rate_limiter is not None:
self._rate_limiter.acquire()
@@ -3064,8 +3063,7 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
"""Internal async chat implementation (extracted for trace wrapping)."""
# Reset the per-turn tool buffer so the self-improve review policy only
# sees tools used in this turn (not during a nested skill-review turn).
if not getattr(self, "_in_skill_review", False):
self._turn_tools_used = []
self._reset_turn_tools()
# C2 - cooperative cancellation: abort early if a pre-set token is given
_cancel = cancel_token if cancel_token is not None else getattr(self, "interrupt_controller", None)
if _cancel is not None and getattr(_cancel, "is_set", lambda: False)():
@@ -3733,8 +3731,20 @@ Output MUST be JSON with 'reflection' and 'satisfactory'.
logging.error(f"Failed to parse tool arguments as JSON: {json_error}")
arguments = {}
# Find the matching tool
tool = next((t for t in tools if t.__name__ == function_name), None)
# Find the matching tool by comparing every supported identifier:
# __name__ (plain callables), .name (BaseTool instances like
# BrowserBaseTool, or aliased FunctionTools), or the class name.
# Compare all candidates (not short-circuit) so an aliased .name
# that differs from __name__ still resolves and BaseTool
# subclasses without __name__ do not crash dispatch.
tool = next(
(t for t in tools if function_name in (
getattr(t, "__name__", None),
getattr(t, "name", None),
type(t).__name__,
)),
None,
)
if not tool:
_get_display_functions()['display_error'](f"Tool {function_name} not found")
continue
@@ -12,7 +12,6 @@ Usage::
"""
import json
import logging
from praisonaiagents._logging import get_logger
import os
import time
@@ -34,7 +34,6 @@ Example:
"""
import os
import logging
from praisonaiagents._logging import get_logger
import time
import asyncio
@@ -125,16 +125,30 @@ class ExecutionMixin:
Args:
prompt: The input prompt to process
**kwargs: Additional arguments passed to achat()
**kwargs: Additional arguments passed to achat():
- return_outcome (bool): If True, return a canonical
``RunOutcome`` (completed | hard_timeout | cancelled |
aborted | failed) instead of raising on error/timeout/
cancellation. Default: False.
- timeout (float): When used with ``return_outcome=True``,
a hard timeout budget for the run.
Returns:
The agent's response as a string, or AutonomyResult if autonomy enabled
The agent's response as a string, or AutonomyResult if autonomy
enabled, or a ``RunOutcome`` when ``return_outcome=True``.
Note:
If autonomy=True was set on the agent, astart() automatically uses
the autonomous loop (run_autonomous_async) instead of single-turn chat.
"""
import sys
return_outcome = kwargs.pop('return_outcome', False)
if return_outcome:
outcome_timeout = kwargs.pop('timeout', None)
return await self._astart_with_outcome(
prompt, outcome_timeout, **kwargs
)
# ─────────────────────────────────────────────────────────────────────
# UNIFIED AUTONOMY API: If autonomy is enabled, route to run_autonomous_async
@@ -196,6 +210,57 @@ class ExecutionMixin:
kwargs['stream'] = stream_requested
return await self.achat(prompt, **kwargs)
async def _astart_with_outcome(self, prompt, timeout=None, **kwargs):
"""Run astart() and normalise its result/exception into a RunOutcome.
Optionally enforces a hard run-level timeout budget. The budget is the
*authoritative* source of ``hard_timeout``: when our own
``asyncio.wait_for`` fires we return ``hard_timeout`` directly, so a
nested operation timeout (which surfaces as a generic
``asyncio.TimeoutError`` from inside the run) is never misreported as a
run-budget timeout — it falls through to ``failed`` via
``RunOutcome.from_exception``.
External ``asyncio.CancelledError`` (e.g. the enclosing task being
cancelled during host shutdown) is re-raised, not swallowed, so
cooperative cancellation semantics are honoured.
"""
import asyncio
from .run_outcome import RunOutcome
enforce_budget = timeout is not None and timeout > 0
# Enforce the run budget with an explicit deadline on a task we own, so
# that only *our* budget expiry maps to hard_timeout. This deliberately
# avoids ``asyncio.wait_for`` catching a bare inner ``TimeoutError``:
# a nested operation timeout raised inside the run must fall through to
# ``failed`` rather than be misreported as a run-budget ``hard_timeout``.
try:
if enforce_budget:
task = asyncio.ensure_future(self.astart(prompt, **kwargs))
try:
done, _ = await asyncio.wait({task}, timeout=timeout)
except asyncio.CancelledError:
# Enclosing task cancelled (e.g. host shutdown): cancel the
# child and propagate so cooperative cancellation is honoured.
task.cancel()
raise
if task not in done:
# Our budget expired first: authoritative, sticky hard_timeout.
task.cancel()
return RunOutcome(reason="hard_timeout")
result = task.result()
else:
result = await self.astart(prompt, **kwargs)
except asyncio.CancelledError:
# External cancellation of the awaiting task: honour asyncio
# cancellation / host shutdown by propagating instead of converting
# it into a benign RunOutcome.
raise
except Exception as exc: # noqa: BLE001 - normalised into outcome
return RunOutcome.from_exception(exc)
return RunOutcome.completed(output=str(result) if result is not None else None)
def run(self, prompt: str, **kwargs: Any) -> Optional[str]:
"""Execute agent silently and return structured result.
@@ -208,9 +273,14 @@ class ExecutionMixin:
**kwargs: Additional arguments:
- stream (bool): Force streaming if True. Default: False
- output (str): Output preset override (rarely needed)
- return_outcome (bool): If True, return a canonical
``RunOutcome`` describing how the run ended
(completed | hard_timeout | cancelled | aborted | failed)
instead of raising on error. Default: False.
Returns:
The agent's response as a string
The agent's response as a string, or a ``RunOutcome`` when
``return_outcome=True``.
Example:
```python
@@ -227,8 +297,14 @@ class ExecutionMixin:
- Background processing
- API endpoints
"""
return_outcome = kwargs.pop('return_outcome', False)
# Check if external managed backend is configured
if hasattr(self, 'backend') and self.backend is not None:
if return_outcome:
return self._run_with_outcome(
lambda: self._delegate_to_backend(prompt, **kwargs)
)
return self._delegate_to_backend(prompt, **kwargs)
# Production defaults: no streaming, no display
@@ -242,17 +318,34 @@ class ExecutionMixin:
# Load history context
self._load_history_context()
# Check if planning mode is enabled
if self.planning:
result = self._start_with_planning(prompt, **kwargs)
else:
result = self.chat(prompt, **kwargs)
# Auto-save session if enabled
self._auto_save_session()
return result
def _execute():
if self.planning:
_result = self._start_with_planning(prompt, **kwargs)
else:
_result = self.chat(prompt, **kwargs)
# Auto-save session if enabled
self._auto_save_session()
return _result
if return_outcome:
return self._run_with_outcome(_execute)
return _execute()
def _run_with_outcome(self, executor):
"""Run ``executor`` and normalise its result/exception into a RunOutcome.
Keeps the canonical terminal-outcome logic in one place so callers get
a single, closed description of how the run ended instead of inferring
it from exception identity.
"""
from .run_outcome import RunOutcome
try:
result = executor()
except BaseException as exc: # noqa: BLE001 - normalised into outcome
return RunOutcome.from_exception(exc)
return RunOutcome.completed(output=str(result) if result is not None else None)
def _delegate_to_backend(self, prompt: str, **kwargs) -> Optional[str]:
"""Delegate execution to external managed backend (e.g., ManagedAgentIntegration).
@@ -1146,13 +1239,9 @@ Write the complete compiled report:"""
# Record the tool name for this turn so the self-improve review policy
# sees async tool usage too (issue #3037). Mirrors the sync path in
# _execute_tool_with_context; skipped during a guarded review turn so
# the review's own calls are not tracked and cannot recurse.
if not getattr(self, "_in_skill_review", False):
turn_tools = getattr(self, "_turn_tools_used", None)
if turn_tools is None:
self._turn_tools_used = []
turn_tools = self._turn_tools_used
turn_tools.append(function_name)
# the review's own calls are not tracked and cannot recurse. Locked so
# concurrent turns on the same Agent don't corrupt the buffer (#3307).
self._record_turn_tool(function_name)
# Enforce BEFORE_TOOL/AFTER_TOOL security hooks for every async caller,
# mirroring the sync execute_tool path in tool_execution.py. Without
@@ -1369,11 +1458,22 @@ Write the complete compiled report:"""
return policy_result # Error dict
_, arguments = policy_result
# Try to find the function in the override tools list first, then agent's tools list
# Try to find the function in the override tools list first, then agent's tools list.
# Resolve by BaseTool/FunctionTool ``.name`` (instances like BrowserBaseTool or
# aliased decorated tools), plain callable ``__name__``, or class name so async
# dispatch matches the robust sync resolution in _execute_tool_impl.
func = None
tools_to_search = tools_override if tools_override is not None else self.tools
from ..tools.base import BaseTool
for tool in tools_to_search:
if (callable(tool) and getattr(tool, '__name__', '') == function_name):
if isinstance(tool, BaseTool) and getattr(tool, 'name', None) == function_name:
func = tool
break
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
@@ -1382,15 +1482,18 @@ Write the complete compiled report:"""
return {"error": f"Function {function_name} not found in tools"}
try:
if inspect.iscoroutinefunction(func):
# BaseTool instances (plugin system, e.g. BrowserBaseTool) are not
# directly callable — dispatch to their .run() method like the sync path.
call_target = func.run if isinstance(func, BaseTool) else func
if inspect.iscoroutinefunction(call_target):
logging.debug(f"Executing async function: {function_name}")
result = await func(**arguments)
result = await call_target(**arguments)
else:
logging.debug(f"Executing sync function in executor: {function_name}")
loop = asyncio.get_running_loop()
from ..trace.context_events import copy_context_to_callable
result = await loop.run_in_executor(
None, copy_context_to_callable(lambda: func(**arguments))
None, copy_context_to_callable(lambda: call_target(**arguments))
)
# Ensure result is JSON serializable
@@ -1474,157 +1577,166 @@ Write the complete compiled report:"""
should_start = False
with _server_lock:
# Initialize port-specific collections if needed
# Initialize port-specific collections if needed (once per port)
if port not in _registered_agents:
_registered_agents[port] = {}
# Initialize shared FastAPI app if not already created for this port
if _shared_apps.get(port) is None:
_shared_apps[port] = FastAPI(
title=f"PraisonAI Agents API (Port {port})",
description="API for interacting with PraisonAI Agents"
# Initialize shared FastAPI app if not already created for this port
if _shared_apps.get(port) is None:
_shared_apps[port] = FastAPI(
title=f"PraisonAI Agents API (Port {port})",
description="API for interacting with PraisonAI Agents"
)
# Add a root endpoint with a welcome message
@_shared_apps[port].get("/")
async def root():
return {
"message": f"Welcome to PraisonAI Agents API on port {port}. See /docs for usage.",
"endpoints": list(_registered_agents[port].keys())
}
# Add healthcheck endpoint
@_shared_apps[port].get("/health")
async def healthcheck():
return {
"status": "ok",
"endpoints": list(_registered_agents[port].keys())
}
# The path registration below must run on EVERY call, not just when the
# port is new, so multiple agents can share a single port.
# Normalize path to ensure it starts with /
if not path.startswith('/'):
path = f'/{path}'
# Check if path is already registered for this port
if path in _registered_agents[port]:
logging.warning(f"Path '{path}' is already registered on port {port}. Please use a different path.")
print(f"⚠️ Warning: Path '{path}' is already registered on port {port}.")
# Use a modified path to avoid conflicts
original_path = path
path = f"{path}_{self.agent_id[:6]}"
logging.warning(f"Using '{path}' instead of '{original_path}'")
print(f"🔄 Using '{path}' instead")
# Register the agent to this path
_registered_agents[port][path] = self.agent_id
# Define the endpoint handler
@_shared_apps[port].post(path)
async def handle_agent_query(request: Request, query_data: Optional[AgentQuery] = None):
# Handle both direct JSON with query field and form data
if query_data is None:
try:
request_data = await request.json()
if "query" not in request_data:
raise HTTPException(status_code=400, detail="Missing 'query' field in request")
query = request_data["query"]
except Exception:
# Fallback to form data or query params
form_data = await request.form()
if "query" in form_data:
query = form_data["query"]
else:
raise HTTPException(status_code=400, detail="Missing 'query' field in request")
else:
query = query_data.query
try:
# Use async version if available, otherwise use sync version
if asyncio.iscoroutinefunction(self.chat):
response = await self.achat(query, task_name=None, task_description=None, task_id=None)
else:
# Run sync function in a thread to avoid blocking
loop = asyncio.get_running_loop()
response = await loop.run_in_executor(None, lambda p=query: self.chat(p))
return {"response": response}
except Exception as e:
logging.error(f"Error processing query: {str(e)}", exc_info=True)
return JSONResponse(
status_code=500,
content={"error": f"Error processing query: {str(e)}"}
)
# Add a root endpoint with a welcome message
@_shared_apps[port].get("/")
async def root():
return {
"message": f"Welcome to PraisonAI Agents API on port {port}. See /docs for usage.",
"endpoints": list(_registered_agents[port].keys())
}
# Invalidate the cached OpenAPI schema so routes registered by later
# shared-port launch() calls still show up in /openapi.json and /docs.
# FastAPI caches app.openapi_schema on first access and does not
# regenerate it when new routes are added afterwards.
_shared_apps[port].openapi_schema = None
# Add healthcheck endpoint
@_shared_apps[port].get("/health")
async def healthcheck():
return {
"status": "ok",
"endpoints": list(_registered_agents[port].keys())
}
print(f"🚀 Agent '{self.name}' available at http://{host}:{port}")
# Normalize path to ensure it starts with /
if not path.startswith('/'):
path = f'/{path}'
# Check if path is already registered for this port
if path in _registered_agents[port]:
logging.warning(f"Path '{path}' is already registered on port {port}. Please use a different path.")
print(f"⚠️ Warning: Path '{path}' is already registered on port {port}.")
# Use a modified path to avoid conflicts
original_path = path
path = f"{path}_{self.agent_id[:6]}"
logging.warning(f"Using '{path}' instead of '{original_path}'")
print(f"🔄 Using '{path}' instead")
# Register the agent to this path
_registered_agents[port][path] = self.agent_id
# Define the endpoint handler
@_shared_apps[port].post(path)
async def handle_agent_query(request: Request, query_data: Optional[AgentQuery] = None):
# Handle both direct JSON with query field and form data
if query_data is None:
try:
request_data = await request.json()
if "query" not in request_data:
raise HTTPException(status_code=400, detail="Missing 'query' field in request")
query = request_data["query"]
except Exception:
# Fallback to form data or query params
form_data = await request.form()
if "query" in form_data:
query = form_data["query"]
else:
raise HTTPException(status_code=400, detail="Missing 'query' field in request")
else:
query = query_data.query
try:
# Use async version if available, otherwise use sync version
if asyncio.iscoroutinefunction(self.chat):
response = await self.achat(query, task_name=None, task_description=None, task_id=None)
else:
# Run sync function in a thread to avoid blocking
loop = asyncio.get_running_loop()
response = await loop.run_in_executor(None, lambda p=query: self.chat(p))
return {"response": response}
except Exception as e:
logging.error(f"Error processing query: {str(e)}", exc_info=True)
return JSONResponse(
status_code=500,
content={"error": f"Error processing query: {str(e)}"}
)
print(f"🚀 Agent '{self.name}' available at http://{host}:{port}")
# Check and mark server as started atomically to prevent race conditions
should_start = not _server_started.get(port, False)
if should_start:
_server_started[port] = True
# Server start/wait outside the lock to avoid holding it during sleep
# Check and mark server as started atomically to prevent race conditions
should_start = not _server_started.get(port, False)
if should_start:
# Start the server in a separate thread
def run_server():
try:
print(f"✅ FastAPI server started at http://{host}:{port}")
print(f"📚 API documentation available at http://{host}:{port}/docs")
print(f"🔌 Available endpoints: {', '.join(list(_registered_agents[port].keys()))}")
uvicorn.run(_shared_apps[port], host=host, port=port, log_level="debug" if debug else "info")
except Exception as e:
logging.error(f"Error starting server: {str(e)}", exc_info=True)
print(f"❌ Error starting server: {str(e)}")
_server_started[port] = True
# Run server in a background thread
server_thread = threading.Thread(target=run_server, daemon=True)
server_thread.start()
# Wait for a moment to allow the server to start and register endpoints
self._safe_sleep(0.5)
else:
# If server is already running, wait a moment to make sure the endpoint is registered
self._safe_sleep(0.1)
print(f"🔌 Available endpoints on port {port}: {', '.join(list(_registered_agents[port].keys()))}")
# Get the stack frame to check if this is the last launch() call in the script
import inspect
stack = inspect.stack()
# If this is called from a Python script (not interactive), try to detect if it's the last launch call
if len(stack) > 1 and stack[1].filename.endswith('.py'):
caller_frame = stack[1]
caller_line = caller_frame.lineno
# Server start/wait outside the lock to avoid holding it during sleep
if should_start:
# Start the server in a separate thread
def run_server():
try:
# Read the file to check if there are more launch calls after this one
with open(caller_frame.filename, 'r') as f:
lines = f.readlines()
# Check if there are more launch() calls after the current line
has_more_launches = False
for line_content in lines[caller_line:]: # renamed line to line_content
if '.launch(' in line_content and not line_content.strip().startswith('#'):
has_more_launches = True
break
# If this is the last launch call, block the main thread
if not has_more_launches:
try:
print("\nAll agents registered for HTTP mode. Press Ctrl+C to stop the servers.")
while True:
self._safe_sleep(1)
except KeyboardInterrupt:
print("\nServers stopped")
print(f"✅ FastAPI server started at http://{host}:{port}")
print(f"📚 API documentation available at http://{host}:{port}/docs")
print(f"🔌 Available endpoints: {', '.join(list(_registered_agents[port].keys()))}")
uvicorn.run(_shared_apps[port], host=host, port=port, log_level="debug" if debug else "info")
except Exception as e:
# If something goes wrong with detection, block anyway to be safe
logging.error(f"Error in launch detection: {e}")
logging.error(f"Error starting server: {str(e)}", exc_info=True)
print(f"❌ Error starting server: {str(e)}")
# Run server in a background thread
server_thread = threading.Thread(target=run_server, daemon=True)
server_thread.start()
# Wait for a moment to allow the server to start and register endpoints
self._safe_sleep(0.5)
else:
# If server is already running, wait a moment to make sure the endpoint is registered
self._safe_sleep(0.1)
print(f"🔌 Available endpoints on port {port}: {', '.join(list(_registered_agents[port].keys()))}")
# Get the stack frame to check if this is the last launch() call in the script
import inspect
stack = inspect.stack()
# If this is called from a Python script (not interactive), try to detect if it's the last launch call
if len(stack) > 1 and stack[1].filename.endswith('.py'):
caller_frame = stack[1]
caller_line = caller_frame.lineno
try:
# Read the file to check if there are more launch calls after this one
with open(caller_frame.filename, 'r') as f:
lines = f.readlines()
# Check if there are more launch() calls after the current line
has_more_launches = False
for line_content in lines[caller_line:]: # renamed line to line_content
if '.launch(' in line_content and not line_content.strip().startswith('#'):
has_more_launches = True
break
# If this is the last launch call, block the main thread
if not has_more_launches:
try:
print("\nKeeping HTTP servers alive. Press Ctrl+C to stop.")
print("\nAll agents registered for HTTP mode. Press Ctrl+C to stop the servers.")
while True:
self._safe_sleep(1)
except KeyboardInterrupt:
print("\nServers stopped")
return None
except Exception as e:
# If something goes wrong with detection, block anyway to be safe
logging.error(f"Error in launch detection: {e}")
try:
print("\nKeeping HTTP servers alive. Press Ctrl+C to stop.")
while True:
self._safe_sleep(1)
except KeyboardInterrupt:
print("\nServers stopped")
return None
def _launch_mcp_server(self, path: str, port: int, host: str, debug: bool):
"""
@@ -1671,7 +1783,7 @@ Write the complete compiled report:"""
base_path = (path or "/mcp").rstrip("/") or "/mcp"
transport = SseServerTransport(f"{base_path}/sse")
starlette_app = Starlette(
routes=[Mount(base_path, mcp.create_app())]
routes=[Mount(base_path, mcp.sse_app())]
)
def run_mcp_server():
@@ -14,9 +14,9 @@ from typing import Optional, Any, Callable, Dict, List, Union, TYPE_CHECKING, Li
from dataclasses import dataclass, field
from enum import Enum
import inspect
import logging
from praisonaiagents._logging import get_logger
import asyncio
import contextvars
import threading
import time
import json
@@ -163,33 +163,50 @@ from ..errors import (
HandoffValidationError
)
# Thread-local storage for tracking handoff chains
_handoff_context = threading.local()
# Per-task/per-thread storage for tracking handoff chains.
#
# ``contextvars.ContextVar`` isolates the chain per :class:`asyncio.Task`
# (and per OS thread), unlike ``threading.local()`` which shares one list
# across every coroutine running on the same event-loop thread. Concurrent
# async handoffs (``asyncio.gather``, a server handling parallel requests, or
# any ``max_concurrent`` workflow) would otherwise push/pop into the same list
# and corrupt each other's cycle/depth state.
_handoff_chain_var: "contextvars.ContextVar[Optional[List[str]]]" = contextvars.ContextVar(
"handoff_chain", default=None
)
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
"""Get current handoff chain for this task/thread."""
chain = _handoff_chain_var.get()
if chain is None:
chain = []
_handoff_chain_var.set(chain)
return 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()
"""Push agent to handoff chain.
Uses copy-on-write so a push made inside a child task does not leak back
into the parent task's chain once the child completes.
"""
chain = list(_get_handoff_chain())
chain.append(agent_name)
_handoff_chain_var.set(chain)
def _pop_handoff() -> Optional[str]:
"""Pop agent from handoff chain."""
chain = _get_handoff_chain()
return chain.pop() if chain else None
chain = list(_get_handoff_chain())
popped = chain.pop() if chain else None
_handoff_chain_var.set(chain)
return popped
def _clear_handoff_chain() -> None:
"""Clear the handoff chain."""
if hasattr(_handoff_context, 'chain'):
_handoff_context.chain = []
_handoff_chain_var.set([])
@dataclass
class HandoffInputData:
@@ -13,7 +13,6 @@ Usage::
"""
import asyncio
import logging
from praisonaiagents._logging import get_logger
import threading
import time
@@ -22,7 +22,6 @@ from __future__ import annotations
import hashlib
import json
import logging
from praisonaiagents._logging import get_logger
import time
from dataclasses import dataclass, field
@@ -8,7 +8,6 @@ Thread-safe implementation for concurrent access.
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
@@ -0,0 +1,138 @@
"""Prompt-cache-stability contract for the Agent turn (Issue #3352).
Provider prompt caching (Anthropic/OpenAI) only hits when the *leading* bytes
of a request are byte-identical to the previous request. For a long-lived
conversation the cached prefix — the system instructions, the serialised tool
schemas, and the model identity — is the dominant cost and latency lever.
Gateways run many users on a single shared ``Agent`` instance and swap
``tools``/``llm`` in and out per turn (per-route tool scoping, per-user
``/model`` override). Those swaps silently change the cached prefix and the
provider cache misses with zero operator visibility.
``prompt_prefix_signature`` gives callers a single, cheap, deterministic
fingerprint of exactly the cache-relevant inputs — model, the sorted set of
tool names, and a fingerprint of the system instructions — and *nothing*
volatile per-turn (arrival time, routing facts, memory/RAG recall). When the
signature is unchanged across turns the prefix is guaranteed stable, so the
provider cache keeps hitting; when it changes, that is the one auditable point
at which cache warmth is knowingly sacrificed.
"""
from __future__ import annotations
import hashlib
from typing import Any
def _tool_name(tool: Any) -> str:
"""Best-effort stable name for a tool entry.
Tools may be plain callables, dicts holding an OpenAI-style function
schema, or objects exposing ``__name__``/``name``. The name identifies the
schema slot in the serialised tool block.
"""
if isinstance(tool, dict):
fn = tool.get("function")
if isinstance(fn, dict) and fn.get("name"):
return str(fn["name"])
for key in ("name", "type"):
if tool.get(key):
return str(tool[key])
return str(sorted(tool.keys()))
for attr in ("__name__", "name"):
value = getattr(tool, attr, None)
if value:
return str(value)
return str(tool)
def _tool_fingerprint(tool: Any) -> str:
"""Best-effort stable fingerprint of a tool's *provider-visible* schema.
The serialised tool block sent to the provider is not just the tool name —
it is the full function schema (name + description + parameters). A change
to a tool's description, parameters, or required fields *without* a rename
changes those bytes and therefore invalidates the prompt cache, so the
fingerprint must reflect the whole schema, not only the name (Issue #3352
review). Falls back to the name when no richer schema is exposed.
"""
name = _tool_name(tool)
# Dict tools already carry an OpenAI-style function schema — fingerprint the
# description + parameters alongside the name so a same-name schema edit is
# detected. ``json.dumps(sort_keys=True)`` makes the render deterministic.
if isinstance(tool, dict):
fn = tool.get("function")
schema = fn if isinstance(fn, dict) else tool
desc = schema.get("description") if isinstance(schema, dict) else None
params = schema.get("parameters") if isinstance(schema, dict) else None
try:
import json
return "\x01".join(
(
name,
str(desc or ""),
json.dumps(params or {}, sort_keys=True, default=str),
)
)
except Exception: # pragma: no cover — defensive
return name
# Callable/object tools: fold in the docstring (the description the schema
# generator emits) so an edited tool doc flips the signature too.
doc = getattr(tool, "__doc__", None)
if doc:
return f"{name}\x01{doc}"
return name
def prompt_prefix_signature(agent: Any) -> str:
"""Return a sha256 signature of an agent's cache-relevant prompt prefix.
The signature is computed over, and only over:
* the model identity (``agent.llm``),
* the sorted set of tool *schema fingerprints* (name + description +
parameters, ``agent.tools``) — so a same-name schema edit is detected,
* a fingerprint of the system instructions (``agent.instructions``).
Volatile per-turn data is intentionally excluded so that an unchanged
route/model keeps a byte-identical prefix and the provider cache keeps
hitting. Callers compare the signature turn-over-turn: an unchanged value
means the cached prefix is reused; a changed value is the single auditable
point of prompt-cache invalidation.
Best-effort and never raises: any attribute access failure degrades the
corresponding component to an empty string rather than breaking the turn.
"""
try:
llm = getattr(agent, "llm", None)
model = llm if isinstance(llm, str) else getattr(llm, "model", None) or str(llm)
except Exception:
model = ""
try:
tools = getattr(agent, "tools", None) or []
tool_fps = sorted(_tool_fingerprint(t) for t in tools)
except Exception:
tool_fps = []
try:
instructions = getattr(agent, "instructions", None) or ""
instructions = str(instructions)
except Exception:
instructions = ""
hasher = hashlib.sha256()
hasher.update(b"model\x00")
hasher.update(str(model).encode("utf-8", "replace"))
hasher.update(b"\x00tools\x00")
hasher.update("\x00".join(tool_fps).encode("utf-8", "replace"))
hasher.update(b"\x00instructions\x00")
hasher.update(instructions.encode("utf-8", "replace"))
return hasher.hexdigest()
__all__ = ["prompt_prefix_signature"]
@@ -6,7 +6,6 @@ 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
@@ -0,0 +1,95 @@
"""Canonical terminal-outcome contract for agent runs.
A single, closed description of *how* a run ended, produced once by the core
run and consumed everywhere. Long-running hosts (e.g. gateways/bots) can make
delivery/retry/DLQ/status decisions from one field instead of inferring the
terminal state from exception identity.
Precedence is explicit and sticky: a ``hard_timeout`` is never silently
downgraded by later cleanup. See ``RunOutcome.from_exception``.
"""
from dataclasses import dataclass
from typing import Optional
try:
from typing import Literal
except ImportError: # pragma: no cover - py<3.8 fallback
Literal = None # type: ignore
if Literal is not None:
TerminalReason = Literal[
"completed", "hard_timeout", "cancelled", "aborted", "failed"
]
else: # pragma: no cover
TerminalReason = str # type: ignore
# Precedence: higher wins and is sticky (a hard timeout is not downgraded).
_REASON_PRECEDENCE = {
"completed": 0,
"failed": 1,
"aborted": 2,
"cancelled": 3,
"hard_timeout": 4,
}
@dataclass(frozen=True)
class RunOutcome:
"""Closed, canonical description of how an agent run ended.
Attributes:
reason: One of ``completed | hard_timeout | cancelled | aborted | failed``.
output: Partial or final text, if any.
error: Redacted message when ``reason == "failed"``.
"""
reason: "TerminalReason"
output: Optional[str] = None
error: Optional[str] = None
@property
def succeeded(self) -> bool:
"""True only when the run completed normally."""
return self.reason == "completed"
@classmethod
def completed(cls, output: Optional[str] = None) -> "RunOutcome":
return cls(reason="completed", output=output)
@classmethod
def from_exception(
cls, exc: BaseException, output: Optional[str] = None
) -> "RunOutcome":
"""Normalise a raised exception into a canonical terminal outcome.
Maps well-known exception types to their terminal reason. Anything
unrecognised is treated as ``failed`` with a redacted message.
Note on ``hard_timeout``: the run-level budget is the authoritative
source of ``hard_timeout`` and is applied explicitly by the caller
(see ``_astart_with_outcome``). A bare ``asyncio.TimeoutError`` reaching
this normaliser is a *nested* operation timeout (e.g. a handoff/tool that
exhausted its own budget while the run budget remained) and is therefore
classified as ``failed`` — not silently promoted to a run-budget
``hard_timeout``, which would drive the wrong host retry/DLQ decision.
Real cooperative cancellation is intercepted and re-raised by the run
wrapper (see ``_astart_with_outcome``) *before* it reaches this
normaliser, so host shutdown is honoured. A supersede/interrupt named
error that does surface here is a domain "cancelled" outcome.
"""
import asyncio
if _name_matches(exc, ("hardtimeout", "runtimeout", "budgettimeout")):
return cls(reason="hard_timeout", output=output)
if isinstance(exc, asyncio.CancelledError) or _name_matches(
exc, ("supersed", "interrupt", "cancelled")
):
return cls(reason="cancelled", output=output)
if _name_matches(exc, ("abort", "drain", "shutdown")):
return cls(reason="aborted", output=output)
return cls(reason="failed", output=output, error=str(exc))
def _name_matches(exc: BaseException, needles: tuple) -> bool:
name = type(exc).__name__.lower()
return any(n in name for n in needles)
@@ -5,7 +5,6 @@ Provides automatic summarization when context window fills up.
Reuses existing telemetry/token_collector for token tracking.
"""
import logging
from praisonaiagents._logging import get_logger
from typing import Optional, List, Dict, Any
@@ -471,6 +471,46 @@ class ToolExecutionMixin:
self._middleware_manager = manager
return manager if manager.has_tool_hooks else None
def _get_turn_tools_lock(self):
"""Return the DualLock guarding the per-turn tool buffer.
Falls back to a lazily-created lock so subclasses or objects that
predate the lock attribute stay safe. The lock protects
``_turn_tools_used`` from corruption when concurrent chat()/achat()
turns run on the same Agent instance (issue #3307).
"""
lock = getattr(self, "_turn_tools_lock", None)
if lock is None:
from .async_safety import DualLock
lock = DualLock()
self._turn_tools_lock = lock
return lock
def _reset_turn_tools(self):
"""Reset the per-turn tool buffer under lock (start of a chat turn)."""
if getattr(self, "_in_skill_review", False):
return
with self._get_turn_tools_lock().sync():
self._turn_tools_used = []
def _record_turn_tool(self, function_name):
"""Append a tool name to the per-turn buffer under lock."""
if getattr(self, "_in_skill_review", False):
return
with self._get_turn_tools_lock().sync():
turn_tools = getattr(self, "_turn_tools_used", None)
if turn_tools is None:
turn_tools = []
self._turn_tools_used = turn_tools
turn_tools.append(function_name)
def _drain_turn_tools(self):
"""Return a copy of the per-turn buffer and clear it, under lock."""
with self._get_turn_tools_lock().sync():
tools_used = list(getattr(self, "_turn_tools_used", []) or [])
self._turn_tools_used = []
return tools_used
def _execute_tool_with_context(self, function_name, arguments, state, tool_call_id=None):
"""Execute tool within injection context, with optional output truncation.
@@ -487,13 +527,9 @@ class ToolExecutionMixin:
# Record the tool name for this turn so the self-improve review policy
# can see what ran (issue #3037). Skipped during a guarded review turn
# to avoid tracking the review's own tool calls or recursing.
if not getattr(self, "_in_skill_review", False):
turn_tools = getattr(self, "_turn_tools_used", None)
if turn_tools is None:
self._turn_tools_used = []
turn_tools = self._turn_tools_used
turn_tools.append(function_name)
# to avoid tracking the review's own tool calls or recursing. Locked so
# concurrent turns on the same Agent don't corrupt the buffer (#3307).
self._record_turn_tool(function_name)
# Emit tool call start event (zero overhead when not set)
_trace_emitter = get_context_emitter()
@@ -1132,8 +1168,9 @@ class ToolExecutionMixin:
# tools_used, so without this the review policy always sees an empty
# list and never runs. Consume the buffer so the next turn starts clean.
if tools_used is None:
tools_used = list(getattr(self, "_turn_tools_used", []) or [])
self._turn_tools_used = []
tools_used = self._drain_turn_tools()
else:
self._drain_turn_tools()
# Trigger AFTER_AGENT hook (only build the input if a hook is actually registered)
from ..hooks import HookEvent
if self._hook_runner.registry.has_hooks(HookEvent.AFTER_AGENT):
@@ -1189,8 +1226,9 @@ class ToolExecutionMixin:
# Default tools_used from the per-turn buffer when the caller did not
# pass it explicitly (issue #3037); mirrors the sync path.
if tools_used is None:
tools_used = list(getattr(self, "_turn_tools_used", []) or [])
self._turn_tools_used = []
tools_used = self._drain_turn_tools()
else:
self._drain_turn_tools()
# Trigger AFTER_AGENT hook (only build the input if a hook is actually registered)
from ..hooks import HookEvent
if self._hook_runner.registry.has_hooks(HookEvent.AFTER_AGENT):
@@ -1395,7 +1433,9 @@ class ToolExecutionMixin:
# only gate the built-in DEFAULT_DANGEROUS_TOOLS and silently skip
# registry-required tools.
approval_registry = get_approval_registry()
registry_required = approval_registry.is_required(tool_name)
registry_required = approval_registry.is_required(
tool_name, getattr(self, 'name', None)
)
# Check if tool needs approval based on multiple criteria
needs_approval = (
approve_all
@@ -1409,7 +1449,7 @@ class ToolExecutionMixin:
tool_name=tool_name,
arguments=tool_args,
risk_level=(
approval_registry.get_risk_level(tool_name)
approval_registry.get_risk_level(tool_name, getattr(self, 'name', None))
or DEFAULT_DANGEROUS_TOOLS.get(tool_name, "medium")
),
agent_name=getattr(self, 'name', None),
@@ -1474,21 +1514,19 @@ class ToolExecutionMixin:
return ApprovalDecision(approved=True, reason="Not a dangerous tool")
else:
# No approval backend configured. An explicit PermissionManager
# ``ask`` rule must still gate the call, so mark it required in the
# approval registry (idempotent) before delegating so the registry
# prompts instead of silently allowing.
if manager_forces_approval:
try:
get_approval_registry().add_requirement(tool_name)
except Exception: # noqa: BLE001
pass
# ``ask`` rule must still gate the call. Rather than mutating shared
# registry state (which leaked onto other agents when this agent had
# no stable name), pass the intent per-call via ``force`` so the
# registry prompts for *this* call only without side effects.
if is_async:
return get_approval_registry().approve_async(
getattr(self, 'name', None), tool_name, tool_args,
force=manager_forces_approval,
)
else:
return get_approval_registry().approve_sync(
getattr(self, 'name', None), tool_name, tool_args,
force=manager_forces_approval,
)
def _permission_manager_requires_approval(self, function_name) -> bool:
@@ -1602,7 +1640,9 @@ class ToolExecutionMixin:
if self._permission_manager_requires_approval(function_name):
return True
from ..approval import get_approval_registry
if get_approval_registry().is_required(function_name):
if get_approval_registry().is_required(
function_name, getattr(self, 'name', None)
):
return True
from ..tools import get_registry as get_tool_registry
if get_tool_registry().get_trust_level(function_name) == "external":
@@ -330,17 +330,26 @@ async def _execute_with_agent_async(executor_agent, task_prompt, task, tools, st
)
def _build_execution_context(agents_instance, task_id):
def _build_execution_context(agents_instance, task_id, skip_memory_init=False):
"""
Build unified execution context for task execution (DRY helper).
Eliminates duplication between sync/async execution paths.
Args:
skip_memory_init: When True, skip the synchronous ``initialize_memory()``
call. The async path (``aexecute_task``) already attempts
``initialize_memory_async()`` beforehand, so this avoids blocking the
event loop on a synchronous ``Memory()`` construction (and a
duplicate backend attempt) if that async init failed.
"""
from .protocols import ExecutionContext
task = agents_instance.tasks[task_id]
# Initialize memory before task execution
if not task.memory:
# Initialize memory before task execution. The async path (aexecute_task)
# already attempts initialize_memory_async() and passes skip_memory_init=True
# so we never block the event loop on a synchronous Memory() construction.
if not task.memory and not skip_memory_init:
task.memory = task.initialize_memory()
executor_agent = task.agent
@@ -842,6 +851,11 @@ class AgentTeam(SpawnAnnounceProtocol):
self._event_bus: Optional[EventBus] = None
self._spawn_lock = threading.RLock() # Thread-safe spawn operations (reentrant)
self._team_id = str(uuid.uuid4()) # Unique team identifier
# Aggregate stream emitter (lazy). Fans in member agents' per-step
# StreamEventEmitter events, tagging each with the emitting agent's id,
# so a single consumer can attribute activity to a specific team member.
self.__stream_emitter = None
self.__stream_fanin_wired = False
# Check for manager_llm in environment variable if not provided
self.manager_llm = manager_llm or os.getenv('OPENAI_MODEL_NAME', 'gpt-4o-mini')
@@ -960,6 +974,63 @@ class AgentTeam(SpawnAnnounceProtocol):
except (ImportError, AttributeError):
self._telemetry = None
@property
def stream_emitter(self):
"""Aggregate ``StreamEventEmitter`` fanning in member agents' events.
Lazily created on first access. On creation it registers a forwarding
callback on each member agent's own ``stream_emitter`` so per-step
events (tool calls, text/reasoning deltas, retries, errors) surface on a
single team-level emitter, each tagged with the emitting agent's
``agent_id``. This gives a single attach point (e.g. the CLI
``--output stream-json`` bridge) parity with single-agent runs.
Zero-overhead when unused: nothing is wired unless this property is
accessed, and forwarding only tags ``agent_id`` when the source event
did not already carry one.
"""
if self.__stream_emitter is None:
try:
from ..streaming.events import StreamEventEmitter
except ImportError:
return None
self.__stream_emitter = StreamEventEmitter()
if not self.__stream_fanin_wired:
self._wire_stream_fanin()
return self.__stream_emitter
def _wire_stream_fanin(self):
"""Forward each member agent's stream events onto the team emitter.
Best-effort and idempotent: an agent whose emitter is unavailable is
skipped, and a forwarding callback is attached at most once per team.
"""
team_emitter = self.__stream_emitter
if team_emitter is None:
return
self.__stream_fanin_wired = True
for agent in self.agents:
member_emitter = getattr(agent, "stream_emitter", None)
if member_emitter is None or not hasattr(member_emitter, "add_callback"):
continue
agent_id = getattr(agent, "agent_id", None) or getattr(agent, "display_name", None)
member_emitter.add_callback(self._make_fanin_callback(team_emitter, agent_id))
@staticmethod
def _make_fanin_callback(team_emitter, agent_id):
"""Build a callback that re-emits an event on the team emitter."""
def _forward(event):
try:
if agent_id is not None and getattr(event, "agent_id", None) is None:
try:
event.agent_id = agent_id
except (AttributeError, TypeError):
pass
team_emitter.emit(event)
except Exception:
logger.debug("AgentTeam stream fan-in forward failed", exc_info=True)
return _forward
def add_task(self, task):
with self._task_id_lock:
task_id = self.task_id_counter
@@ -1054,8 +1125,17 @@ class AgentTeam(SpawnAnnounceProtocol):
if task.status == "not started":
task.status = "in progress"
# Build execution context using DRY helper
context = _build_execution_context(self, task_id)
# Initialize memory asynchronously to avoid blocking the event loop on
# synchronous Memory() construction. The shared helper's own
# `if not task.memory:` guard makes this a safe no-op for the sync path.
if not task.memory:
await task.initialize_memory_async()
# Build execution context using DRY helper. skip_memory_init=True prevents
# the helper from falling back to the *synchronous* initialize_memory()
# (which would block the event loop and duplicate a failed backend attempt)
# when the async init above did not populate task.memory.
context = _build_execution_context(self, task_id, skip_memory_init=True)
# Execute with agent using DRY helper
agent_output = await _execute_with_agent_async(
@@ -17,7 +17,6 @@ Usage:
result = auto_rag.chat("Hello!") # Skips retrieval
"""
import logging
from praisonaiagents._logging import get_logger
import time
from dataclasses import dataclass, field
@@ -5,7 +5,6 @@ Provides delegation primitives for spawning subagents with scoped permissions
and context. Inspired by Gemini CLI's delegate-to-agent pattern.
"""
import logging
from praisonaiagents._logging import get_logger
import asyncio
import warnings
@@ -11,7 +11,6 @@ Provides lightweight backends that ship with the core SDK:
from __future__ import annotations
import asyncio
import logging
from praisonaiagents._logging import get_logger
from typing import Any
@@ -20,7 +20,6 @@ import asyncio
import contextvars
import hashlib
import json
import logging
from praisonaiagents._logging import get_logger
import os
from typing import Dict, List, Optional, Set
@@ -91,10 +90,19 @@ class ApprovalRegistry:
self._global_backend = None # type: ignore[assignment]
self._agent_backends: Dict[str, object] = {}
# Tool requirements (mirrors old APPROVAL_REQUIRED_TOOLS / TOOL_RISK_LEVELS)
# Tool requirements (mirrors old APPROVAL_REQUIRED_TOOLS / TOOL_RISK_LEVELS).
# These hold process-wide defaults (e.g. DEFAULT_DANGEROUS_TOOLS and any
# intentional global registration).
self._required_tools: Set[str] = set()
self._risk_levels: Dict[str, str] = {}
# Per-agent tool requirements. A PermissionManager ``ask`` rule belongs
# to a single agent, so it must not leak an approval gate onto unrelated
# agents sharing the same process. Mirrors the agent-keyed pattern used
# by ``_agent_backends`` / ``_agent_tool_auto_approve``.
self._agent_required_tools: Dict[str, Set[str]] = {}
self._agent_risk_levels: Dict[tuple[str, str], str] = {}
# Per-agent, per-tool auto-approval (G-A fix)
self._agent_tool_auto_approve: Dict[tuple[str, str], bool] = {}
@@ -153,18 +161,51 @@ class ApprovalRegistry:
# ── Tool requirement management ──────────────────────────────────────
def add_requirement(self, tool_name: str, risk_level: str = "high") -> None:
self._required_tools.add(tool_name)
self._risk_levels[tool_name] = risk_level
def add_requirement(
self,
tool_name: str,
risk_level: str = "high",
agent_name: Optional[str] = None,
) -> None:
"""Mark *tool_name* as requiring approval.
def remove_requirement(self, tool_name: str) -> None:
self._required_tools.discard(tool_name)
self._risk_levels.pop(tool_name, None)
When *agent_name* is given the requirement is scoped to that agent only
(used for per-agent ``PermissionManager`` ``ask`` rules), so it never
forces approval onto other agents in the same process. Omitting
*agent_name* keeps the historical process-wide behaviour used for
genuinely dangerous tools registered at startup.
"""
if agent_name:
self._agent_required_tools.setdefault(agent_name, set()).add(tool_name)
self._agent_risk_levels[(agent_name, tool_name)] = risk_level
else:
self._required_tools.add(tool_name)
self._risk_levels[tool_name] = risk_level
def is_required(self, tool_name: str) -> bool:
def remove_requirement(
self, tool_name: str, agent_name: Optional[str] = None
) -> None:
if agent_name:
tools = self._agent_required_tools.get(agent_name)
if tools is not None:
tools.discard(tool_name)
self._agent_risk_levels.pop((agent_name, tool_name), None)
else:
self._required_tools.discard(tool_name)
self._risk_levels.pop(tool_name, None)
def is_required(self, tool_name: str, agent_name: Optional[str] = None) -> bool:
if agent_name and tool_name in self._agent_required_tools.get(agent_name, ()):
return True
return tool_name in self._required_tools
def get_risk_level(self, tool_name: str) -> Optional[str]:
def get_risk_level(
self, tool_name: str, agent_name: Optional[str] = None
) -> Optional[str]:
if agent_name:
level = self._agent_risk_levels.get((agent_name, tool_name))
if level is not None:
return level
return self._risk_levels.get(tool_name)
# ── Per-tool auto-approval (G-A fix) ─────────────────────────────────
@@ -346,10 +387,17 @@ class ApprovalRegistry:
agent_name: Optional[str],
tool_name: str,
arguments: Dict,
force: bool = False,
) -> ApprovalDecision:
"""Synchronous approval — used by ``Agent._execute_tool_impl``."""
# Fast-path: not required
if not self.is_required(tool_name):
"""Synchronous approval — used by ``Agent._execute_tool_impl``.
``force`` gates this single call even when the tool is not otherwise
registered as requiring approval (e.g. a per-agent ``PermissionManager``
``ask`` rule). It applies only to this call and never mutates shared
registry state, so it cannot leak an approval gate onto other agents.
"""
# Fast-path: not required (checks both global and this agent's scope)
if not force and not self.is_required(tool_name, agent_name):
return ApprovalDecision(approved=True, reason="No approval required")
# Already approved in this context
@@ -381,7 +429,7 @@ class ApprovalRegistry:
request = ApprovalRequest(
tool_name=tool_name,
arguments=arguments,
risk_level=self._risk_levels.get(tool_name, "medium"),
risk_level=self.get_risk_level(tool_name, agent_name) or "medium",
agent_name=agent_name,
)
@@ -406,10 +454,15 @@ class ApprovalRegistry:
agent_name: Optional[str],
tool_name: str,
arguments: Dict,
force: bool = False,
) -> ApprovalDecision:
"""Asynchronous approval — used by async tool execution path."""
# Fast-path: not required
if not self.is_required(tool_name):
"""Asynchronous approval — used by async tool execution path.
See :meth:`approve_sync` for the ``force`` semantics (per-call gate,
no shared-state mutation).
"""
# Fast-path: not required (checks both global and this agent's scope)
if not force and not self.is_required(tool_name, agent_name):
return ApprovalDecision(approved=True, reason="No approval required")
if self.is_already_approved(tool_name, arguments):
@@ -437,7 +490,7 @@ class ApprovalRegistry:
request = ApprovalRequest(
tool_name=tool_name,
arguments=arguments,
risk_level=self._risk_levels.get(tool_name, "medium"),
risk_level=self.get_risk_level(tool_name, agent_name) or "medium",
agent_name=agent_name,
)
@@ -5,7 +5,6 @@ Manages background task execution.
"""
import asyncio
import logging
import threading
from praisonaiagents._logging import get_logger
from typing import Optional, List, Dict, Any, Callable, Union
@@ -6,7 +6,6 @@ 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
@@ -33,6 +33,9 @@ from .protocols import (
WebhookVerifierProtocol,
CallbackPayloadStoreProtocol,
InMemoryCallbackPayloadStore,
GatewayRuntimeSeams,
SupportsGatewayRuntime,
GatewayAdapterContractError,
)
from .base import (
BasePlatformAdapter,
@@ -122,6 +125,9 @@ __all__ = [
"WebhookVerifierProtocol",
"CallbackPayloadStoreProtocol",
"InMemoryCallbackPayloadStore",
"GatewayRuntimeSeams",
"SupportsGatewayRuntime",
"GatewayAdapterContractError",
"BasePlatformAdapter",
"SendResult",
"InteractiveContext",
@@ -302,6 +302,79 @@ class WebhookVerifierProtocol(Protocol):
...
class GatewayAdapterContractError(TypeError):
"""Raised when a channel adapter cannot receive the gateway runtime seams.
The gateway wires four reliability seams into every channel adapter —
the cross-platform identity resolver, the delivery router, the admission
gate, and the shared per-turn lock map. When the gateway has these seams
to inject but the adapter neither implements
:class:`SupportsGatewayRuntime` nor exposes a compatible session, the wiring
would silently no-op and the adapter would run without admission control,
durable delivery routing, or cross-platform turn locking. Failing loudly
with this error surfaces the missing contract instead.
"""
@dataclass
class GatewayRuntimeSeams:
"""The gateway reliability seams handed to a channel adapter at build time.
A single, typed carrier for the four runtime seams the gateway injects so
an adapter wires them up in one place instead of via four duck-typed
private-attribute splices:
Attributes:
identity_resolver: Cross-platform identity resolver; unifies the same
human across platforms onto one session key.
delivery_router: Backing router for the built-in ``send_message`` tool,
so an agent turn can proactively reach the user mid-task.
admission_gate: Gateway-wide admission control (concurrency ceiling /
fair queue / backpressure) applied to inbound runs.
turn_lock_map: Shared per-turn lock map for cross-platform turn
serialisation on the resolved session id.
A seam left ``None`` means the gateway has nothing to inject for it and the
adapter should keep whatever it already has.
"""
identity_resolver: Optional[Any] = None
delivery_router: Optional[Any] = None
admission_gate: Optional[Any] = None
turn_lock_map: Optional[Any] = None
@runtime_checkable
class SupportsGatewayRuntime(Protocol):
"""Contract for channel adapters that accept the gateway runtime seams.
Instead of the gateway reaching into an adapter's private session and
splicing ``_identity_resolver`` / ``_delivery_router`` / ``_admission_gate``
/ ``_locks`` via ``getattr``/``hasattr`` (which silently no-ops on any
adapter whose session does not match the built-in shape), an adapter — in
tree or ``pip``-installed — implements this one method. The gateway calls it
once with a :class:`GatewayRuntimeSeams`, so the same reliability guarantees
(admission/backpressure, delivery routing, cross-platform turn locking)
hold for *every* adapter.
Adapters whose ``__init__`` creates a ``BotSessionManager`` get this for
free — the session manager implements ``attach_gateway_runtime`` and the
adapter can simply delegate to ``self._session.attach_gateway_runtime(...)``.
"""
def attach_gateway_runtime(self, runtime: "GatewayRuntimeSeams") -> None:
"""Wire the gateway runtime seams into this adapter.
Only seams present (non-``None``) on ``runtime`` should be applied;
seams left ``None`` mean the gateway has nothing to inject and the
adapter must keep its existing value.
Args:
runtime: The gateway reliability seams to attach.
"""
...
class MessageType(str, Enum):
"""Types of bot messages."""
@@ -5,7 +5,6 @@ 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
@@ -7,7 +7,6 @@ Implements shadow git repository for file-level checkpointing.
import os
import re
import asyncio
import logging
from praisonaiagents._logging import get_logger
import shutil
from typing import Optional, List, Dict, Any, Callable
@@ -160,7 +160,8 @@ class ContextCompactor:
)
except Exception:
pass
return max(1, len(text) // 4)
from ..context.tokens import estimate_tokens_heuristic
return estimate_tokens_heuristic(text)
def count_message_tokens(self, message: Dict[str, Any]) -> int:
"""Count tokens in a message, including tool_calls payloads."""
@@ -8,7 +8,6 @@ The implementation is extracted from workflows.py _evaluate_condition()
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
@@ -950,7 +950,16 @@ class ExecutionConfig:
if isinstance(context_compaction, dict):
from ..context.policy import ContextCompactionPolicy
context_compaction = ContextCompactionPolicy.from_dict(context_compaction)
# Handle compaction_strategy restoration (serialised as a string value in to_dict)
compaction_strategy = data.get("compaction_strategy")
if isinstance(compaction_strategy, str):
from ..compaction.strategy import CompactionStrategy
try:
compaction_strategy = CompactionStrategy(compaction_strategy)
except ValueError:
compaction_strategy = None
return cls(
max_iter=data.get("max_iter", 20),
max_steps=data.get("max_steps", None),
@@ -958,13 +967,17 @@ class ExecutionConfig:
max_rpm=data.get("max_rpm", None),
max_execution_time=data.get("max_execution_time", None),
max_retry_limit=data.get("max_retry_limit", 2),
retry_initial_delay=data.get("retry_initial_delay", 1.0),
retry_backoff_factor=data.get("retry_backoff_factor", 2.0),
retry_jitter=data.get("retry_jitter", 0.1),
code_execution=data.get("code_execution", False),
code_mode=data.get("code_mode", "safe"),
code_sandbox_mode=data.get("code_sandbox_mode", "docker"),
code_sandbox_mode=data.get("code_sandbox_mode", "sandbox"),
code_tools=data.get("code_tools", False),
code_tools_allow=data.get("code_tools_allow", None),
context_compaction=context_compaction,
max_context_tokens=data.get("max_context_tokens", None),
compaction_strategy=compaction_strategy,
max_budget=data.get("max_budget", None),
parallel_tool_calls=data.get("parallel_tool_calls", False),
)
@@ -50,42 +50,6 @@ def detect_url_scheme(value: str) -> Optional[str]:
return None
def parse_url_to_config(
url: str,
config_class: type,
url_schemes: Dict[str, str],
) -> Any:
"""
Parse a URL string into a config object.
Args:
url: URL string (e.g., "postgresql://localhost/db")
config_class: Config dataclass to instantiate
url_schemes: Mapping of URL schemes to backend names
Returns:
Config instance with backend and url set
Raises:
ValueError: If URL scheme is not supported
"""
scheme = detect_url_scheme(url)
if not scheme:
raise ValueError(f"Invalid URL format: {url}")
if scheme not in url_schemes:
valid_schemes = ", ".join(sorted(url_schemes.keys()))
raise ValueError(
f"Unsupported URL scheme '{scheme}' in '{url}'. "
f"Supported schemes: {valid_schemes}"
)
backend = url_schemes[scheme]
# Create config with backend and URL in config dict
return config_class(backend=backend, config={"url": url})
def is_path_like(value: str) -> bool:
"""
Check if a string looks like a file path. O(1) operation.
@@ -136,21 +100,6 @@ def is_path_like(value: str) -> bool:
return False
def is_numeric_string(value: str) -> bool:
"""
Check if a string is numeric. O(1) operation.
Args:
value: String to check
Returns:
True if string is numeric
"""
if not isinstance(value, str):
return False
return value.isdigit()
def suggest_similar(value: str, candidates: Iterable[str], max_distance: int = 2) -> Optional[str]:
"""
Find the most similar string from candidates using Levenshtein distance.
@@ -246,28 +195,6 @@ def make_preset_error(
return ValueError(" ".join(msg_parts))
def make_array_error(
param_name: str,
value: list,
expected_format: str,
) -> ValueError:
"""
Create a helpful error message for invalid array format.
Args:
param_name: Name of the parameter
value: Invalid array value
expected_format: Description of expected format
Returns:
ValueError with helpful message
"""
return ValueError(
f"Invalid {param_name} array format: {value}. "
f"Expected: {expected_format}"
)
def is_policy_string(value: str) -> bool:
"""
Check if a string is a policy specification. O(1) operation.
@@ -6,7 +6,6 @@ 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
@@ -12,7 +12,6 @@ Design principles:
"""
import asyncio
import logging
from praisonaiagents._logging import get_logger
from typing import Optional, List
@@ -12,7 +12,6 @@ Design principles:
- Preserves most relevant content
"""
import logging
from praisonaiagents._logging import get_logger
from typing import Protocol, Optional, List
from dataclasses import dataclass
@@ -7,7 +7,6 @@ Injects FastContext results into the main agent with:
- Precision over recall (avoid context pollution)
"""
import logging
from praisonaiagents._logging import get_logger
from typing import Optional, List, Dict, Any
from dataclasses import dataclass
@@ -25,7 +25,6 @@ Example usage:
import os
import hashlib
import json
import logging
from praisonaiagents._logging import get_logger
from typing import Optional, List, Dict, Any
@@ -10,7 +10,6 @@ This agent is designed for fast context retrieval using:
import os
import json
import logging
from praisonaiagents._logging import get_logger
from typing import List, Dict, Any, Optional
@@ -15,7 +15,6 @@ Design principles:
import os
import json
import hashlib
import logging
from praisonaiagents._logging import get_logger
from dataclasses import dataclass, field, asdict
from pathlib import Path
@@ -12,7 +12,6 @@ import os
import fnmatch
import hashlib
import json
import logging
from praisonaiagents._logging import get_logger
from dataclasses import dataclass
from typing import Dict, List, Set, Optional, Any
@@ -1,318 +0,0 @@
"""
File Watcher for Incremental Indexing.
Monitors file system changes and triggers incremental index updates:
- Watches for file creation, modification, deletion
- Debounces rapid changes
- Supports background indexing
"""
import os
import time
import logging
from praisonaiagents._logging import get_logger
import threading
from typing import Dict, Set, Callable, Optional, Any
from dataclasses import dataclass
from enum import Enum
logger = get_logger(__name__)
class ChangeType(Enum):
"""Types of file system changes."""
CREATED = "created"
MODIFIED = "modified"
DELETED = "deleted"
@dataclass
class FileChange:
"""Represents a file system change.
Attributes:
path: Path to the changed file
change_type: Type of change
timestamp: When the change was detected
"""
path: str
change_type: ChangeType
timestamp: float
class FileWatcher:
"""Watches for file system changes and triggers callbacks.
Uses polling-based approach for cross-platform compatibility.
For production use, consider using watchdog library.
Attributes:
workspace_path: Root directory to watch
extensions: File extensions to watch
poll_interval: Seconds between polls
"""
def __init__(
self,
workspace_path: str,
extensions: Optional[Set[str]] = None,
poll_interval: float = 1.0,
debounce_delay: float = 0.5,
on_change: Optional[Callable[[FileChange], None]] = None
):
"""Initialize file watcher.
Args:
workspace_path: Root directory to watch
extensions: File extensions to watch (None = all)
poll_interval: Seconds between polls
debounce_delay: Delay before processing changes
on_change: Callback for file changes
"""
self.workspace_path = os.path.abspath(workspace_path)
self.extensions = extensions or {
'.py', '.js', '.ts', '.jsx', '.tsx', '.go', '.rs', '.java',
'.c', '.cpp', '.h', '.hpp', '.cs', '.rb', '.php', '.swift'
}
self.poll_interval = poll_interval
self.debounce_delay = debounce_delay
self.on_change = on_change
# State tracking
self._file_mtimes: Dict[str, float] = {}
self._pending_changes: Dict[str, FileChange] = {}
self._running = False
self._thread: Optional[threading.Thread] = None
self._lock = threading.Lock()
def _scan_files(self) -> Dict[str, float]:
"""Scan workspace and get file modification times.
Returns:
Dict mapping file paths to modification times
"""
mtimes = {}
for root, dirs, files in os.walk(self.workspace_path):
# Skip hidden directories
dirs[:] = [d for d in dirs if not d.startswith('.')]
for filename in files:
ext = os.path.splitext(filename)[1].lower()
if ext in self.extensions:
file_path = os.path.join(root, filename)
try:
mtimes[file_path] = os.path.getmtime(file_path)
except OSError:
pass
return mtimes
def _detect_changes(self, new_mtimes: Dict[str, float]) -> None:
"""Detect changes between old and new file states.
Args:
new_mtimes: New file modification times
"""
old_paths = set(self._file_mtimes.keys())
new_paths = set(new_mtimes.keys())
now = time.time()
# Detect created files
for path in new_paths - old_paths:
self._add_pending_change(FileChange(
path=path,
change_type=ChangeType.CREATED,
timestamp=now
))
# Detect deleted files
for path in old_paths - new_paths:
self._add_pending_change(FileChange(
path=path,
change_type=ChangeType.DELETED,
timestamp=now
))
# Detect modified files
for path in old_paths & new_paths:
if new_mtimes[path] > self._file_mtimes[path]:
self._add_pending_change(FileChange(
path=path,
change_type=ChangeType.MODIFIED,
timestamp=now
))
self._file_mtimes = new_mtimes
def _add_pending_change(self, change: FileChange) -> None:
"""Add a change to pending queue (with debouncing).
Args:
change: File change to add
"""
with self._lock:
self._pending_changes[change.path] = change
def _process_pending_changes(self) -> None:
"""Process pending changes after debounce delay."""
with self._lock:
now = time.time()
to_process = []
for path, change in list(self._pending_changes.items()):
if now - change.timestamp >= self.debounce_delay:
to_process.append(change)
del self._pending_changes[path]
# Process changes outside lock
for change in to_process:
if self.on_change:
try:
self.on_change(change)
except Exception as e:
logger.error(f"Error processing change {change.path}: {e}")
def _poll_loop(self) -> None:
"""Main polling loop."""
# Initial scan
self._file_mtimes = self._scan_files()
while self._running:
try:
# Scan for changes
new_mtimes = self._scan_files()
self._detect_changes(new_mtimes)
# Process pending changes
self._process_pending_changes()
except Exception as e:
logger.error(f"Error in file watcher: {e}")
time.sleep(self.poll_interval)
def start(self) -> None:
"""Start watching for file changes."""
if self._running:
return
self._running = True
self._thread = threading.Thread(target=self._poll_loop, daemon=True)
self._thread.start()
logger.info(f"File watcher started for {self.workspace_path}")
def stop(self) -> None:
"""Stop watching for file changes."""
self._running = False
if self._thread:
self._thread.join(timeout=2.0)
self._thread = None
logger.info("File watcher stopped")
def __enter__(self):
self.start()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.stop()
class IncrementalIndexer:
"""Manages incremental index updates based on file changes.
Combines FileIndexer/SymbolIndexer with FileWatcher for
automatic index updates when files change.
"""
def __init__(
self,
workspace_path: str,
file_indexer: Optional[Any] = None,
symbol_indexer: Optional[Any] = None,
poll_interval: float = 2.0
):
"""Initialize incremental indexer.
Args:
workspace_path: Root directory to index
file_indexer: FileIndexer instance (optional)
symbol_indexer: SymbolIndexer instance (optional)
poll_interval: Seconds between file system polls
"""
self.workspace_path = os.path.abspath(workspace_path)
self.file_indexer = file_indexer
self.symbol_indexer = symbol_indexer
self._watcher = FileWatcher(
workspace_path=workspace_path,
poll_interval=poll_interval,
on_change=self._handle_change
)
# Statistics
self.changes_processed = 0
self.last_change_time: Optional[float] = None
def _handle_change(self, change: FileChange) -> None:
"""Handle a file change.
Args:
change: File change to process
"""
rel_path = os.path.relpath(change.path, self.workspace_path)
logger.debug(f"Processing {change.change_type.value}: {rel_path}")
if change.change_type == ChangeType.DELETED:
# Remove from indexes
if self.file_indexer and hasattr(self.file_indexer, 'files'):
self.file_indexer.files.pop(rel_path, None)
if self.symbol_indexer and hasattr(self.symbol_indexer, 'symbols'):
self.symbol_indexer.symbols.pop(rel_path, None)
else:
# Re-index the file
if self.file_indexer and hasattr(self.file_indexer, 'index_file'):
# FileIndexer doesn't have index_file, so we skip
pass
if self.symbol_indexer and hasattr(self.symbol_indexer, 'index_file'):
self.symbol_indexer.index_file(change.path)
self.changes_processed += 1
self.last_change_time = time.time()
def start(self) -> None:
"""Start incremental indexing."""
# Initial full index
if self.file_indexer:
self.file_indexer.index()
if self.symbol_indexer:
self.symbol_indexer.index()
# Start watching
self._watcher.start()
def stop(self) -> None:
"""Stop incremental indexing."""
self._watcher.stop()
def get_stats(self) -> Dict[str, Any]:
"""Get indexer statistics.
Returns:
Dictionary with stats
"""
stats = {
"changes_processed": self.changes_processed,
"last_change_time": self.last_change_time
}
if self.file_indexer:
stats["file_indexer"] = self.file_indexer.get_stats()
if self.symbol_indexer:
stats["symbol_indexer"] = self.symbol_indexer.get_stats()
return stats
def __enter__(self):
self.start()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.stop()
@@ -11,7 +11,6 @@ Extracts code symbols from source files:
import os
import re
import logging
from praisonaiagents._logging import get_logger
from dataclasses import dataclass, field
from typing import Dict, List, Set, Optional, Any
@@ -11,7 +11,6 @@ Provides async parallel execution of search tools with:
import asyncio
from concurrent.futures import ThreadPoolExecutor
from typing import List, Dict, Any, Optional, Callable
import logging
from praisonaiagents._logging import get_logger
import time
@@ -11,7 +11,6 @@ Design principles:
- No performance impact on default behavior
"""
import logging
from praisonaiagents._logging import get_logger
from typing import Protocol, List, Dict, Any, Optional, runtime_checkable
@@ -1,366 +0,0 @@
"""
Search Strategy for Fast Context.
Orchestrates multi-turn search with:
- Turn 1-3: Exploration (grep, glob, directory listing)
- Turn 4: Final answer (file list + line ranges)
- Early termination if sufficient context found
"""
import logging
from praisonaiagents._logging import get_logger
from dataclasses import dataclass, field
from typing import List, Dict, Any, Optional, Set
from enum import Enum
from praisonaiagents.context.fast.result import FastContextResult, FileMatch, LineRange
from praisonaiagents.context.fast.parallel_executor import ToolCallBatch
logger = get_logger(__name__)
class SearchPhase(Enum):
"""Phases of the search strategy."""
DISCOVERY = "discovery" # Turn 1: Discover structure
EXPLORATION = "exploration" # Turn 2-3: Deep search
REFINEMENT = "refinement" # Turn 4: Final answer
@dataclass
class SearchState:
"""Tracks the state of a multi-turn search.
Attributes:
query: Original search query
current_turn: Current turn number (1-indexed)
max_turns: Maximum turns allowed
phase: Current search phase
discovered_files: Files found so far
explored_paths: Paths already explored
result: Accumulated search result
should_terminate: Whether to terminate early
"""
query: str
current_turn: int = 0
max_turns: int = 4
phase: SearchPhase = SearchPhase.DISCOVERY
discovered_files: Set[str] = field(default_factory=set)
explored_paths: Set[str] = field(default_factory=set)
result: FastContextResult = field(default_factory=FastContextResult)
should_terminate: bool = False
# Thresholds for early termination
min_files_for_termination: int = 5
max_files_before_refinement: int = 20
def advance_turn(self) -> None:
"""Advance to the next turn and update phase."""
self.current_turn += 1
if self.current_turn == 1:
self.phase = SearchPhase.DISCOVERY
elif self.current_turn < self.max_turns:
self.phase = SearchPhase.EXPLORATION
else:
self.phase = SearchPhase.REFINEMENT
def check_early_termination(self) -> bool:
"""Check if search should terminate early.
Returns:
True if search should terminate
"""
# Terminate if we have enough high-quality results
if len(self.discovered_files) >= self.min_files_for_termination:
high_relevance = sum(
1 for f in self.result.files
if f.relevance_score >= 0.8
)
if high_relevance >= 3:
self.should_terminate = True
return True
# Terminate if we've explored everything
if self.current_turn >= 2 and not self._has_unexplored_paths():
self.should_terminate = True
return True
return False
def _has_unexplored_paths(self) -> bool:
"""Check if there are unexplored paths."""
# Simple heuristic: if we found files but haven't explored many paths
return len(self.discovered_files) > len(self.explored_paths) * 2
class SearchStrategy:
"""Orchestrates multi-turn search strategy.
Implements the Fast Context search approach:
- Turn 1: Discovery - understand codebase structure
- Turn 2-3: Exploration - deep search for relevant code
- Turn 4: Refinement - finalize results
Supports early termination when sufficient context is found.
"""
def __init__(
self,
workspace_path: str,
max_turns: int = 4,
max_parallel: int = 8
):
"""Initialize search strategy.
Args:
workspace_path: Root directory for searches
max_turns: Maximum search turns
max_parallel: Maximum parallel tool calls per turn
"""
self.workspace_path = workspace_path
self.max_turns = max_turns
self.max_parallel = max_parallel
def create_state(self, query: str) -> SearchState:
"""Create a new search state.
Args:
query: Search query
Returns:
New SearchState instance
"""
state = SearchState(query=query, max_turns=self.max_turns)
state.result.query = query
return state
def plan_discovery_turn(self, state: SearchState) -> ToolCallBatch:
"""Plan the discovery turn (Turn 1).
Focus on understanding codebase structure:
- List root directory
- Find common file patterns
- Initial grep for query terms
Args:
state: Current search state
Returns:
Batch of tool calls to execute
"""
batch = ToolCallBatch(max_size=self.max_parallel)
query = state.query
# List root directory
batch.add("list_directory", dir_path=self.workspace_path, recursive=False)
# Find Python files (most common)
batch.add("glob_search", search_path=self.workspace_path, pattern="**/*.py", max_results=20)
# Initial grep for query terms
query_words = query.lower().split()
for word in query_words[:3]: # First 3 words
if len(word) >= 3: # Skip short words
batch.add("grep_search", search_path=self.workspace_path, pattern=word, max_results=10)
if batch.is_full:
break
return batch
def plan_exploration_turn(self, state: SearchState) -> ToolCallBatch:
"""Plan an exploration turn (Turn 2-3).
Deep search based on discovery results:
- Search in discovered directories
- Read promising files
- Follow references
Args:
state: Current search state
Returns:
Batch of tool calls to execute
"""
batch = ToolCallBatch(max_size=self.max_parallel)
# Read top files found so far
for file_match in state.result.files[:4]:
if file_match.path not in state.explored_paths:
batch.add("read_file", filepath=file_match.path, context_lines=5)
state.explored_paths.add(file_match.path)
if batch.is_full:
break
# Search in unexplored directories
unexplored_dirs = self._find_unexplored_dirs(state)
for dir_path in unexplored_dirs[:2]:
batch.add("list_directory", dir_path=dir_path, recursive=True, max_depth=2)
if batch.is_full:
break
# Additional grep searches with refined patterns
if not batch.is_full:
refined_patterns = self._generate_refined_patterns(state)
for pattern in refined_patterns[:2]:
batch.add("grep_search", search_path=self.workspace_path, pattern=pattern, max_results=15)
if batch.is_full:
break
return batch
def plan_refinement_turn(self, state: SearchState) -> ToolCallBatch:
"""Plan the refinement turn (Turn 4).
Finalize results:
- Read remaining important files
- Get specific line ranges
Args:
state: Current search state
Returns:
Batch of tool calls to execute
"""
batch = ToolCallBatch(max_size=self.max_parallel)
# Read top files that haven't been fully explored
for file_match in state.result.files[:self.max_parallel]:
if file_match.path not in state.explored_paths:
# Read specific line ranges if available
if file_match.line_ranges:
for lr in file_match.line_ranges[:2]:
batch.add(
"read_file",
filepath=file_match.path,
start_line=max(1, lr.start - 5),
end_line=lr.end + 5
)
if batch.is_full:
break
else:
batch.add("read_file", filepath=file_match.path)
state.explored_paths.add(file_match.path)
if batch.is_full:
break
return batch
def plan_next_turn(self, state: SearchState) -> Optional[ToolCallBatch]:
"""Plan the next turn based on current state.
Args:
state: Current search state
Returns:
Batch of tool calls, or None if search should end
"""
state.advance_turn()
# Check for early termination
if state.should_terminate or state.current_turn > state.max_turns:
return None
if state.check_early_termination():
return None
# Plan based on phase
if state.phase == SearchPhase.DISCOVERY:
return self.plan_discovery_turn(state)
elif state.phase == SearchPhase.EXPLORATION:
return self.plan_exploration_turn(state)
else: # REFINEMENT
return self.plan_refinement_turn(state)
def process_results(
self,
state: SearchState,
tool_results: List[Any]
) -> None:
"""Process results from a turn and update state.
Args:
state: Current search state
tool_results: Results from tool execution
"""
for result in tool_results:
if isinstance(result, list):
# Grep or glob results
for item in result:
if isinstance(item, dict):
path = item.get("path", "")
if path:
state.discovered_files.add(path)
# Create or update file match
file_match = FileMatch(
path=path,
relevance_score=0.8,
match_count=1
)
# Add line range if available
line_num = item.get("line_number")
if line_num:
file_match.add_line_range(LineRange(
start=max(1, line_num - 2),
end=line_num + 2,
content=item.get("context"),
relevance_score=0.8
))
state.result.add_file(file_match)
elif isinstance(result, dict):
# Read file or list directory result
if result.get("success"):
path = result.get("path", "")
if path:
state.explored_paths.add(path)
# Handle directory listing
entries = result.get("entries", [])
for entry in entries:
if not entry.get("is_dir"):
state.discovered_files.add(entry.get("path", ""))
def _find_unexplored_dirs(self, state: SearchState) -> List[str]:
"""Find directories that haven't been explored.
Args:
state: Current search state
Returns:
List of unexplored directory paths
"""
import os
# Extract unique directories from discovered files
dirs = set()
for file_path in state.discovered_files:
dir_path = os.path.dirname(file_path)
if dir_path and dir_path not in state.explored_paths:
dirs.add(dir_path)
return list(dirs)[:5] # Limit to 5
def _generate_refined_patterns(self, state: SearchState) -> List[str]:
"""Generate refined search patterns based on results.
Args:
state: Current search state
Returns:
List of refined search patterns
"""
patterns = []
query_words = state.query.lower().split()
# Combine query words
if len(query_words) >= 2:
patterns.append(f"{query_words[0]}.*{query_words[1]}")
# Add common code patterns
for word in query_words[:2]:
if len(word) >= 3:
patterns.append(f"def {word}")
patterns.append(f"class {word}")
return patterns[:4]
@@ -15,7 +15,6 @@ import re
import fnmatch
from pathlib import Path
from typing import List, Dict, Any, Optional, Set
import logging
from praisonaiagents._logging import get_logger
logger = get_logger(__name__)
@@ -9,7 +9,6 @@ from dataclasses import dataclass, field, asdict
from typing import Any, Dict, List, Optional
from datetime import datetime, timezone
import json
import logging
from praisonaiagents._logging import get_logger
logger = get_logger(__name__)
@@ -18,7 +18,6 @@ Zero Performance Impact:
import threading
import json
import logging
from praisonaiagents._logging import get_logger
from typing import Dict, List, Any, Optional
from dataclasses import dataclass
@@ -10,7 +10,6 @@ from typing import Any, Dict, List, Optional
from enum import Enum
import time
import hashlib
import logging
from praisonaiagents._logging import get_logger
logger = get_logger(__name__)
@@ -5,7 +5,6 @@ Provides lightweight tracing and metrics collection for escalation execution.
Opt-in only - no overhead when not enabled.
"""
import logging
from praisonaiagents._logging import get_logger
import time
from dataclasses import dataclass, field
@@ -4,7 +4,6 @@ Escalation Pipeline for PraisonAI Agents.
Implements progressive escalation from direct response to full autonomous mode.
"""
import logging
from praisonaiagents._logging import get_logger
import time
from typing import Any, Dict, List, Optional, Callable
@@ -5,7 +5,6 @@ Evaluates agent output accuracy by comparing against expected output using LLM-a
"""
import os
import logging
from praisonaiagents._logging import get_logger
from typing import Callable, Optional, Union, TYPE_CHECKING
@@ -7,7 +7,6 @@ This module provides the abstract base class that all evaluators inherit from.
from abc import ABC, abstractmethod
from typing import Any, Dict, Optional, Union, TYPE_CHECKING
import uuid
import logging
from praisonaiagents._logging import get_logger
if TYPE_CHECKING:
@@ -5,7 +5,6 @@ Evaluates agent outputs against custom criteria using LLM-as-judge.
"""
import os
import logging
from praisonaiagents._logging import get_logger
from typing import Callable, Literal, Optional, Union, TYPE_CHECKING
@@ -9,7 +9,6 @@ that was duplicated across multiple evaluators.
"""
import os
import logging
from praisonaiagents._logging import get_logger
from dataclasses import dataclass, field, asdict
from datetime import datetime, timezone
@@ -15,7 +15,6 @@ Example:
"""
import os
import logging
from praisonaiagents._logging import get_logger
from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Type, TYPE_CHECKING
@@ -18,7 +18,6 @@ Example:
import time
import math
import logging
from praisonaiagents._logging import get_logger
from typing import TYPE_CHECKING, Optional, Callable, Any, List
from dataclasses import dataclass
@@ -7,7 +7,6 @@ and file-based verification for audio/video.
"""
import os
import logging
from praisonaiagents._logging import get_logger
from dataclasses import dataclass, field
from typing import Any, Dict, Literal, Optional
@@ -5,7 +5,6 @@ Measures runtime and memory usage of agent executions or functions.
"""
import time
import logging
from praisonaiagents._logging import get_logger
from typing import Callable, Optional, TYPE_CHECKING
@@ -4,7 +4,6 @@ Reliability evaluator for PraisonAI Agents.
Evaluates agent reliability by verifying expected tool calls are made.
"""
import logging
from praisonaiagents._logging import get_logger
from typing import Dict, List, Optional, Set, Any, TYPE_CHECKING
@@ -18,7 +18,6 @@ Example:
... # Split into chunks
"""
import logging
from praisonaiagents._logging import get_logger
from typing import Dict, Optional, Union
@@ -3,7 +3,6 @@ Utility functions for PraisonAI Agents evaluation framework.
"""
import json
import logging
from praisonaiagents._logging import get_logger
from pathlib import Path
from typing import Any, Dict, Optional, Union
@@ -70,6 +70,10 @@ from .protocols import (
GatewayConcurrencyPolicyProtocol,
GatewayConcurrencyPolicy, # backward-compat alias
ConcurrencyLimitPolicy,
# Gateway resource-pressure admission (Issue #3445)
ResourceSample,
ResourcePressurePolicyProtocol,
MemoryPressurePolicy,
# Gateway rate-limit admission (Issue #2532)
RateLimitDecision,
RateLimitPolicyProtocol,
@@ -277,6 +281,10 @@ __all__ = [
"GatewayConcurrencyPolicyProtocol",
"GatewayConcurrencyPolicy",
"ConcurrencyLimitPolicy",
# Gateway resource-pressure admission (Issue #3445)
"ResourceSample",
"ResourcePressurePolicyProtocol",
"MemoryPressurePolicy",
# Gateway rate-limit admission (Issue #2532)
"RateLimitDecision",
"RateLimitPolicyProtocol",
@@ -63,6 +63,9 @@ class SessionConfig:
max_messages: Maximum messages to keep in history (0 = unlimited)
persist: Whether to persist session state
persist_path: Path for session persistence
store: Persistence backend when ``persist`` is set — ``"sqlite"``
(default: transcripts in a WAL SQLite DB with concurrent readers
and indexed lookups) or ``"file"`` (legacy per-session JSON files)
resume_window: How long (seconds) a session stays resumable after disconnect
max_inbox: Maximum queued messages per session (0 = unlimited, default 256)
metadata: Additional session metadata
@@ -73,6 +76,7 @@ class SessionConfig:
max_messages: int = 1000
persist: bool = False
persist_path: Optional[str] = None
store: str = "sqlite" # "sqlite" (concurrent, indexed) | "file" (legacy JSON)
resume_window: int = 86400 # 24 hours default
max_inbox: int = 256 # Default bounded queue size
metadata: Dict[str, Any] = field(default_factory=dict)
@@ -90,6 +94,10 @@ class SessionConfig:
raise ValueError("max_messages must be >= 0")
if self.resume_window < 0:
raise ValueError("resume_window must be >= 0")
if self.store not in ("sqlite", "file"):
raise ValueError(
f"Invalid session store {self.store!r}; expected 'sqlite' or 'file'"
)
def to_dict(self) -> Dict[str, Any]:
"""Convert to dictionary."""
@@ -98,6 +106,7 @@ class SessionConfig:
"max_messages": self.max_messages,
"persist": self.persist,
"persist_path": self.persist_path,
"store": self.store,
"resume_window": self.resume_window,
"max_inbox": self.max_inbox,
"metadata": self.metadata,
@@ -685,6 +694,7 @@ class MultiChannelGatewayConfig:
max_messages=sc_data.get("max_messages", 1000),
persist=sc_data.get("persist", False),
persist_path=sc_data.get("persist_path"),
store=sc_data.get("store", "sqlite"),
resume_window=sc_data.get("resume_window", 86400),
max_inbox=sc_data.get("max_inbox", 256),
metadata=sc_data.get("metadata", {}),
@@ -2928,6 +2928,135 @@ class ConcurrencyLimitPolicy:
GatewayConcurrencyPolicy = GatewayConcurrencyPolicyProtocol
# ---------------------------------------------------------------------------
# Gateway resource-pressure admission (Issue #3445)
#
# Admission today is concurrency/CPU-scaled and blind to memory; on a small
# always-on host a burst of concurrent turns drives RSS up until the OOM
# killer fires — the failure a $5 box hits first. This adds a pure, import-
# free decision that maps a resource *sample* (current RSS) onto the existing
# :class:`AdmissionDecision` so the gate can queue under soft pressure and
# shed under hard pressure *before* the process is killed. It reuses the
# admission seam (no new subsystem) and sits beside the concurrency / rate-
# limit / scale-to-zero policy family. The live sampler (reading
# ``resource.getrusage`` / optional ``psutil``) and the wiring into the gate
# live in the wrapper; this contract keeps the decision testable in isolation.
# ---------------------------------------------------------------------------
@dataclass(frozen=True)
class ResourceSample:
"""A point-in-time snapshot of the gateway process's resource usage.
Attributes:
rss_mb: Resident set size in mebibytes, or ``None`` when the platform
cannot report it (the policy then admits and self-disables so the
monitor never crashes the gateway it protects).
"""
rss_mb: Optional[float] = None
@runtime_checkable
class ResourcePressurePolicyProtocol(Protocol):
"""Protocol for memory/resource-aware admission decisions.
Pure, import-free decision contract consumed by the wrapper's admission
gate. The wrapper samples its own resource usage on a lightweight cadence
and hands the policy a :class:`ResourceSample`; the policy returns an
:class:`AdmissionDecision` — ``ADMIT`` below the soft threshold, ``QUEUE``
to apply backpressure above it, and ``REJECT`` above the hard threshold so
the process sheds load before the OOM killer fires. Sampling and
enforcement (the ``asyncio.Semaphore`` ceiling and bounded wait queue)
live in the wrapper; this keeps the *decision* provable in isolation,
symmetric with :class:`GatewayConcurrencyPolicyProtocol`.
A config-driven default (:class:`MemoryPressurePolicy`) is provided for
the common "soft/hard RSS threshold" case.
"""
def evaluate(self, sample: ResourceSample) -> AdmissionDecision:
"""Return an :class:`AdmissionDecision` for the supplied sample."""
...
class MemoryPressurePolicy:
"""Config-driven RSS-threshold resource-pressure policy.
The default wired by the ``max_rss_mb`` gateway config key
(``BotOS(max_rss_mb=...)`` / ``gateway.yaml``) and the
``AdmissionGate(resource_policy=...)`` Python surface. It is intentionally
minimal and dependency-free so the decision lives in core and is provable
in isolation; the wrapper owns the live sampler and the side effects
(queue / shed / busy ack).
The decision, given a sample's ``rss_mb``:
* ``ADMIT`` while ``rss_mb < soft_rss_mb`` (or the platform can't report
memory, so ``rss_mb is None`` — never block on a missing signal).
* ``QUEUE`` (apply backpressure) while ``soft_rss_mb <= rss_mb <
hard_rss_mb``.
* ``REJECT`` (shed with a busy ack) while ``rss_mb >= hard_rss_mb``.
A ``hard_rss_mb`` of ``0`` disables pressure-based shedding entirely
(every sample admits) — the legacy default when no threshold is set.
Example::
MemoryPressurePolicy(soft_rss_mb=400, hard_rss_mb=550)
"""
def __init__(
self,
soft_rss_mb: float = 0.0,
hard_rss_mb: float = 0.0,
):
try:
soft = float(soft_rss_mb or 0.0)
except (TypeError, ValueError) as err:
raise ValueError(
f"soft_rss_mb must be a number, got {soft_rss_mb!r}"
) from err
try:
hard = float(hard_rss_mb or 0.0)
except (TypeError, ValueError) as err:
raise ValueError(
f"hard_rss_mb must be a number, got {hard_rss_mb!r}"
) from err
if soft < 0:
raise ValueError(f"soft_rss_mb must be >= 0, got {soft_rss_mb!r}")
if hard < 0:
raise ValueError(f"hard_rss_mb must be >= 0, got {hard_rss_mb!r}")
# A soft threshold above the hard one would queue turns that should be
# shed; fail fast rather than silently invert the pressure ladder.
if soft and hard and soft > hard:
raise ValueError(
f"soft_rss_mb ({soft_rss_mb!r}) must be <= "
f"hard_rss_mb ({hard_rss_mb!r})"
)
self.soft_rss_mb = soft
self.hard_rss_mb = hard
@property
def enabled(self) -> bool:
"""Whether pressure-based admission is active (a threshold is set)."""
return self.soft_rss_mb > 0 or self.hard_rss_mb > 0
def evaluate(self, sample: ResourceSample) -> AdmissionDecision:
# Disabled, or the platform can't report memory: never block on a
# missing/absent signal — admit and let concurrency limits apply.
if not self.enabled:
return AdmissionDecision.ADMIT
rss = getattr(sample, "rss_mb", None)
if rss is None:
return AdmissionDecision.ADMIT
if self.hard_rss_mb and rss >= self.hard_rss_mb:
return AdmissionDecision.REJECT
if self.soft_rss_mb and rss >= self.soft_rss_mb:
return AdmissionDecision.QUEUE
return AdmissionDecision.ADMIT
# ---------------------------------------------------------------------------
# Gateway rate-limit admission (Issue #2532)
#
@@ -5,7 +5,6 @@ This module provides LLM-powered guardrails that can validate task outputs
using natural language descriptions, similar to CrewAI's implementation.
"""
import logging
from praisonaiagents._logging import get_logger
from typing import Any, Tuple, Union, Optional, Dict
from pydantic import BaseModel
@@ -1,13 +0,0 @@
"""Hooks query protocol for UI/API consumers."""
from __future__ import annotations
from typing import Dict, List, Protocol, runtime_checkable
@runtime_checkable
class HooksQueryProtocol(Protocol):
"""Read path for registered hooks."""
def list_hooks_for_api(self) -> List[Dict]:
...
@@ -4,7 +4,6 @@ Hook Registry for PraisonAI Agents.
Manages registration and lookup of hooks for different events.
"""
import logging
import threading
from praisonaiagents._logging import get_logger
from typing import Dict, List, Optional, Callable, Union
@@ -9,7 +9,6 @@ import os
import json
import time
import asyncio
import logging
from praisonaiagents._logging import get_logger
import subprocess
from typing import List, Optional, Dict, Any
@@ -36,6 +36,12 @@ class HookEvent(str, Enum):
# LLM lifecycle
BEFORE_LLM = "before_llm"
AFTER_LLM = "after_llm"
# Prompt-cache stability (advisory): fired when a turn's cached prompt
# prefix (model + tool schemas + system-prompt fingerprint) changes from
# the previous turn, so a long-lived conversation's provider prompt cache
# will miss. Payload carries the old/new signature and a reason.
PROMPT_PREFIX_INVALIDATED = "prompt_prefix_invalidated"
# Error handling
ON_ERROR = "on_error"
@@ -7,7 +7,6 @@ Handles all normalization to ensure metadata is ALWAYS a dict (never None).
LAZY IMPORT: mem0 is only imported when this adapter is instantiated.
"""
import logging
from praisonaiagents._logging import get_logger
import os
from typing import Any, Dict, List, Optional
@@ -8,7 +8,6 @@ LAZY IMPORT: pymongo is only imported when this adapter is instantiated.
"""
import os
import logging
from praisonaiagents._logging import get_logger
from datetime import datetime
from typing import Any, Dict, List, Optional
@@ -10,7 +10,6 @@ Implementations are provided by the wrapper layer.
from dataclasses import dataclass, field
from typing import Any, Callable, Dict, List, Optional, Protocol, runtime_checkable
from enum import Enum
import logging
from praisonaiagents._logging import get_logger
import math
@@ -10,7 +10,6 @@ Implementations are provided by the wrapper layer.
from dataclasses import dataclass, field
from typing import Any, Callable, Dict, List, Optional, Protocol, runtime_checkable
from enum import Enum
import logging
from praisonaiagents._logging import get_logger
logger = get_logger(__name__)
@@ -10,7 +10,6 @@ Implementations are provided by the wrapper layer (praisonai.adapters.readers).
from dataclasses import dataclass, field
from typing import Any, Callable, Dict, List, Optional, Protocol, runtime_checkable
import os
import logging
from praisonaiagents._logging import get_logger
logger = get_logger(__name__)
@@ -9,7 +9,6 @@ Implementations are provided by praisonai-tools or wrapper layer.
from dataclasses import dataclass
from typing import Any, Callable, Dict, List, Optional, Protocol, runtime_checkable
import logging
from praisonaiagents._logging import get_logger
logger = get_logger(__name__)
@@ -10,7 +10,6 @@ Implementations are provided by the wrapper layer.
from dataclasses import dataclass, field
from typing import Any, Callable, Dict, List, Optional, Protocol, runtime_checkable
from enum import Enum
import logging
from praisonaiagents._logging import get_logger
logger = get_logger(__name__)
@@ -9,7 +9,6 @@ Implementations are provided by praisonai-tools or wrapper layer.
from dataclasses import dataclass, field
from typing import Any, Callable, Dict, List, Optional, Protocol, runtime_checkable
import logging
from praisonaiagents._logging import get_logger
logger = get_logger(__name__)
@@ -10,7 +10,6 @@ Heavy implementations live in the praisonai wrapper.
from __future__ import annotations
import logging
from praisonaiagents._logging import get_logger
import time
from dataclasses import dataclass, field
@@ -714,30 +714,6 @@ Respond with ONLY a valid JSON tool call in this format:
return any(indicator in error_str or indicator in error_type for indicator in indicators)
def _classify_error_and_should_retry_legacy(self, error: Exception, attempt: int = 1) -> tuple[str, bool, float]:
"""Legacy error classification - deprecated, use resolve_failover_decision() instead.
Args:
error: Exception to classify
attempt: Current attempt number (1-based)
Returns:
Tuple of (category, should_retry, retry_delay)
"""
import warnings
warnings.warn(
"_classify_error_and_should_retry is deprecated, use resolve_failover_decision() instead",
DeprecationWarning,
stacklevel=2
)
# Delegate to new typed classification system
decision = self.resolve_failover_decision(error, {"attempt": attempt, "max_retries": self._max_retries})
return decision.reason, decision.is_retryable, decision.backoff_ms / 1000.0
# Backward compatibility alias for existing code
_classify_error_and_should_retry = _classify_error_and_should_retry_legacy
def classify_error_kind(self, error: Exception) -> AgentErrorKind:
"""
Classify error into typed AgentErrorKind instead of freeform strings.
@@ -6,7 +6,6 @@ LLM model/provider based on task complexity, cost considerations, and model capa
"""
import os
import logging
from praisonaiagents._logging import get_logger
from typing import Dict, List, Optional, Tuple
from dataclasses import dataclass
@@ -23,7 +23,6 @@ Usage:
import time
import asyncio
import logging
import threading
from praisonaiagents._logging import get_logger
from dataclasses import dataclass, field
@@ -7,7 +7,6 @@ Provides Language Server Protocol client implementation.
import os
import json
import asyncio
import logging
from praisonaiagents._logging import get_logger
from typing import Optional, List, Dict, Any
from pathlib import Path
@@ -282,7 +282,20 @@ class MCP:
agent.start("What is the stock price of Tesla?")
```
"""
# Process-level registry of sanitized MCP server names that have been
# namespaced via with_tool_prefix(), mirroring how tools/registry.py tracks
# tool names. Lets skills' CapabilityValidator discover connected servers
# instead of always failing closed (issue #3307).
_active_server_names: set = set()
_active_server_names_lock = threading.Lock()
@classmethod
def list_active_server_names(cls) -> set:
"""Return the set of sanitized names of MCP servers namespaced this run."""
with cls._active_server_names_lock:
return set(cls._active_server_names)
def __init__(self, command_or_string=None, args=None, *, command=None, timeout=60, debug=False,
allowed_tools: Optional[List[str]] = None, disabled_tools: Optional[List[str]] = None, **kwargs):
"""
@@ -834,6 +847,15 @@ class MCP:
self._tool_prefix = sanitized
# Record this server in the process-level registry so skills'
# CapabilityValidator can discover it (issue #3307). Store both the
# original name and its sanitized form so a skill requirement matches
# regardless of which spelling it declares.
with type(self)._active_server_names_lock:
if prefix:
type(self)._active_server_names.add(prefix)
type(self)._active_server_names.add(sanitized)
# Rename already-generated callable tools. Dispatch inside each
# wrapper closes over the original tool name, so only the public
# __name__/__qualname__ needs updating for schema construction.
Loaded 100 of 276 files, more files were not shown because too many files have changed in this diff. Show more