Skip to content

feat(extensions): add AgentcoreSession.invoke - #972

Merged
ParidelPooya merged 5 commits into
mainfrom
feat/agentcore-session-e6
Nov 21, 2026
Merged

ParidelPooya merged 5 commits into
mainfrom
feat/agentcore-session-e6

Conversation

@ParidelPooya

@ParidelPooya ParidelPooya commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

AgentcoreSession.invoke(context, name, *, job_input, options) sends one job to the session and returns the job's result.

Why

agentcore_session creates and stops a session, but its handler cannot send a job yet. This change adds the job call.

Change

  • AgentcoreSession is now a concrete class, as MicrovmSession is. The session handler receives it. The private _SessionHandle is removed.
  • invoke builds the job scope with _AgentcoreScope.create. It turns the session config and the job options into an AgentcoreConfig. So the name, timeout, heartbeat and input-size checks of agentcore() run before any durable operation, without copied code.
  • invoke runs the job with _run_job and a stop that does nothing. So a failed job leaves the session running. The session stops after its handler, as before.
  • agentcore_session and AgentcoreSession are exported from compute.agentcore.

What I copied from MicrovmSession.invoke:

  1. Each job runs in its own child context named name, in the context passed to invoke. Its operations are <name>.callback and <name>.request.
  2. The job's child context has no subtype, as in a MicroVM session job. The callback and request steps keep their AgentCore subtypes from _run_job.
  3. invoke converts the job's ChildContextError back to its AgentCore class with AgentcoreError.from_child_context_error.
  4. agentcore_session converts a ChildContextError back only when its cause is an AgentCore error, as microvm_session does. Every other handler error stays ChildContextError.
  5. AgentcoreSession keeps the context that agentcore_session was called with. invoke raises TypeError for that context before any durable operation or AgentCore request. The error message matches the MicroVM one.

What I did not copy: the session timeout field is unchanged; #970 removes it. The session child context has no subtype yet; E7 (#945) adds it.

Testing

  • AgentCore tests: 84 passed. Extensions suite: 623 passed. mypy src tests: no issues. hatch fmt --check and lintcommit.py: pass.
  • New tests:
    1. Two jobs in a row send the same runtimeSessionId as the stop call, and each job has its own callback ID.
    2. A failed, timed-out or undelivered job reaches the handler as AgentcoreJobFailedError, AgentcoreTimeoutError or AgentcoreDeliveryError.
    3. A job error that leaves the handler reaches the caller with its own class, and the session stops once.
    4. A failed job does not stop the session. The next job runs, then the stop.
    5. An input over MAX_JOB_INPUT_BYTES fails before any job operation.
    6. invoke with the outer context raises TypeError. No InvokeAgentRuntime request is sent, and the session records only review.session and review.stop.
  • Mutation checks, each made at least one new or existing test fail:
    1. Without the invoke error conversion: 5 tests fail.
    2. Without the agentcore_session error conversion: test 3 fails.
    3. With the real stop instead of the no-op: tests 3 and 4 fail.
    4. With the agentcore_session conversion for every error: 2 existing tests fail.
    5. Without the outer-context check: test 6 fails.

Closes #944
Part of #954
Twin: aws/aws-durable-execution-sdk-js#1235

AgentcoreSession is now a class, as MicrovmSession is. The session
handler receives it instead of the private handle.

invoke runs one job in a child context named after the job. It
builds the job scope with _AgentcoreScope.create, so it checks the
name, the timeouts and the input size before any durable operation.
It runs the job with _run_job and a stop that does nothing. So a
failed job leaves the session running, and the session stops after
its handler.

A job error leaves the job's child context as ChildContextError.
invoke and agentcore_session restore an AgentCore error to its own
class, as microvm_session does. Other handler errors stay
ChildContextError.

agentcore_session is now exported from compute.agentcore.
The invoke call forwards qualifier, retry_strategy and
heartbeat_timeout to the job. No test covered these forwards. A new
session test sets all three, and checks the request, the retry and
the job payload.

The agentcore_session docstring now says that an AgentCore error that
leaves a child context the handler created reaches the caller as
ChildContextError. The invoke docstring lists AttributeError and the
invalid JSON result. The _AgentcoreScope docstring names invoke.
Resolve conflicts from the extras to extensions package rename in #975.
@ParidelPooya ParidelPooya changed the title feat(extras): add AgentcoreSession.invoke feat(extensions): add AgentcoreSession.invoke Nov 20, 2026
The session handler must pass its own context to invoke. A job made in
the outer context runs, and the next replay then fails. So
AgentcoreSession keeps the outer context, and invoke raises TypeError
for it before any request, as MicrovmSession.invoke does.

@yaythomas yaythomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@ParidelPooya
ParidelPooya marked this pull request as ready for review November 21, 2026 00:32
@ParidelPooya
ParidelPooya deployed to ai-pr-review-runtime November 21, 2026 00:32 — with GitHub Actions Active
@ParidelPooya
ParidelPooya merged commit 764e950 into main Nov 21, 2026
20 checks passed
@ParidelPooya
ParidelPooya deleted the feat/agentcore-session-e6 branch November 21, 2026 00:32

This branch was successfully deployed

1 active deployment
ai-pr-review-runtime — f67f2453 Deployed Nov 21, 2026 by ParidelPooya via notify / Generate notification summary #475
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.

[AgentCore session] E6: Add session.invoke

2 participants