Skip to content

feat(python-sdk): expose subagent task query API#39

Merged
ZhiXiao-Lin merged 1 commit into
mainfrom
feat/subagent-python-sdk
May 23, 2026
Merged

feat(python-sdk): expose subagent task query API#39
ZhiXiao-Lin merged 1 commit into
mainfrom
feat/subagent-python-sdk

Conversation

@ZhiXiao-Lin
Copy link
Copy Markdown
Contributor

Stacked on #38#37#36#35. Base retargets to `main` automatically as upstream PRs land.

Summary

Mirrors the new `AgentSession` subagent query API (introduced in #35) onto the Python SDK so callers can introspect delegated subagent tasks symmetrically with the Node SDK (#37).

```python
snap = session.subagent_task('task-abc')

dict with keys: task_id, parent_session_id, child_session_id, agent,

description, status, started_ms, updated_ms, finished_ms?, output?,

success?, progress: [...] (status ∈ {'running','completed','failed'})

or None when the task id is unknown.

all_tasks = session.subagent_tasks() # list (this session, oldest first)
pending = session.pending_subagent_tasks() # list (status == 'running' only)
```

Each binding follows the existing run-query pattern: drops the GIL via `py.allow_threads`, blocks on the shared tokio runtime, then serializes the result through serde_json so Python sees plain `dict` / `list` / `None`.

Test plan

  • `cargo check --lib` on the Python SDK crate is clean.
  • `maturin build --release` produces a wheel.
  • New `tests/test_subagent_query_api.py` runs the wheel in a venv and asserts:
    • `subagent_tasks()` → `[]` for a fresh session
    • `pending_subagent_tasks()` → `[]` for a fresh session
    • `subagent_task('task-does-not-exist')` → `None`
  • Smoke uses an inline ACL string, so no real provider credentials are needed.

Follow-ups

@ZhiXiao-Lin ZhiXiao-Lin changed the base branch from fix/sdk-types-stability to main May 23, 2026 15:53
@ZhiXiao-Lin ZhiXiao-Lin force-pushed the feat/subagent-python-sdk branch from 7fad254 to df5b49a Compare May 23, 2026 16:01
Mirrors the new Session APIs onto the Python SDK so callers can
introspect delegated subagent tasks symmetrically with the Node SDK.

- `Session.subagent_task(task_id)` → dict or None
- `Session.subagent_tasks()` → list of dicts (this session)
- `Session.pending_subagent_tasks()` → only `running` entries

Each method follows the existing run-query pattern: drop the GIL via
`py.allow_threads`, block on the tokio runtime, then serialize the
result via serde_json so Python sees plain dict / list / None.

Smoke test under `tests/test_subagent_query_api.py` confirms the three
methods exist and return the expected empty-state shapes for a fresh
session, without needing real LLM credentials.
@ZhiXiao-Lin ZhiXiao-Lin force-pushed the feat/subagent-python-sdk branch from df5b49a to cc20a8d Compare May 23, 2026 16:11
@ZhiXiao-Lin ZhiXiao-Lin merged commit 79c43c7 into main May 23, 2026
1 check passed
@ZhiXiao-Lin ZhiXiao-Lin deleted the feat/subagent-python-sdk branch May 23, 2026 16:12
@ZhiXiao-Lin ZhiXiao-Lin mentioned this pull request May 23, 2026
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants