Skip to content

Conversation

@AbirAbbas
Copy link
Contributor

Summary

  • Add ctx property to Agent class for direct access to execution context during reasoner/skill execution
  • Returns None outside of active execution to prevent accidental use of stale context
  • Fix integration test fixtures to support current monorepo structure

Motivation

Previously, accessing the execution context required importing a separate function:

from agentfield.execution_context import get_current_context

@app.reasoner()
async def handle_ticket(ticket_id: str):
    ctx = get_current_context()
    await app.memory.workflow(ctx.workflow_id).set("status", "processing")

Now users can access it directly via app.ctx:

@app.reasoner()
async def handle_ticket(ticket_id: str):
    await app.memory.workflow(app.ctx.workflow_id).set("status", "processing")

Behavior

Scenario app.ctx returns
Inside reasoner/skill (via HTTP request) Valid ExecutionContext
Inside nested agent call Valid child ExecutionContext
Outside any execution None
After request completes None

This matches the behavior of app.memory which also returns None outside of execution.

Test plan

  • Unit tests verify ctx returns None outside execution
  • Unit tests verify ctx returns context during execution
  • Unit tests verify ctx ignores unregistered contexts
  • Integration test verifies end-to-end behavior (requires FTS5-enabled SQLite)
  • All 371 existing tests pass

🤖 Generated with Claude Code

AbirAbbas and others added 3 commits December 1, 2025 10:18
Add a `ctx` property to the Agent class that provides direct access to
the current execution context during reasoner/skill execution. This
enables a more ergonomic API:

Before:
  from agentfield.execution_context import get_current_context
  ctx = get_current_context()
  workflow_id = ctx.workflow_id

After:
  workflow_id = app.ctx.workflow_id

The property returns None when accessed outside of an active execution
(e.g., at module level or after a request completes), matching the
behavior of app.memory. This prevents accidental use of stale or
placeholder context data.

Also fixes integration test fixtures to support the current monorepo
structure where control-plane lives at repo root instead of
apps/platform/agentfield.

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

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The integration tests should skip gracefully in CI when the control
plane cannot be built. Reverting conftest changes that caused the
tests to attempt building when they should skip.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@AbirAbbas AbirAbbas merged commit 6369050 into main Dec 1, 2025
18 checks passed
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