Skip to content

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

Draft
ParidelPooya wants to merge 1 commit into
mainfrom
feat/agentcore-session-e6
Draft

ParidelPooya wants to merge 1 commit into
mainfrom
feat/agentcore-session-e6

Conversation

@ParidelPooya

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.

What I did not copy: MicrovmSession.invoke refuses the outer context with a TypeError. That is a guard for a developer mistake, so it is left out. The session timeout field is unchanged; #970 removes it. The session child context has no subtype yet; E7 (#945) adds it.

Testing

  • AgentCore tests: 82 passed. Extras suite: 621 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.
  • 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.

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.

This branch has not been deployed

No deployments
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

1 participant