Repository navigation
feat(extras): add AgentcoreSession.invoke - #1264
Draft
ParidelPooya wants to merge 1 commit into
Draft
ParidelPooya wants to merge 1 commit into
ParidelPooya wants to merge 1 commit into
Conversation
The agentcoreSession handler now receives an AgentcoreSession. Its invoke runs one job in the session through runJob, in a child context named after the job, in the context passed to invoke. The session stops the session, so the job's stop does nothing. A job failure keeps its Agentcore* class in the handler and after it leaves the session, as in microvmSession. agentcoreSession is exported from the compute/agentcore entry point. Closes #1235
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
session.invoke(context, name, input, options)toagentcoreSession. One call runs one job in the session and returns the job's result.Why
agentcoreSession(#1260) creates the session and stops it, but its handler cannot send a job yet. This item adds the job call.Change
AgentcoreSession. The internalAgentcoreSessionHandletype is removed.invokeruns one job with the existingrunJobhelper, in a child context named after the job, in thecontextpassed toinvoke. It passes astopthat does nothing, because the session stops the session in its ownfinally.invokereads the Region and encodes the input with the existingfunctionRegionandencodeInputfromagentcore.ts, which are now exported inside the package. So an input error rejects the returned promise before any durable operation of the job, as inagentcore().agentcoreErrorMapper(jobName). So a failed job rejects inside the handler asAgentcoreJobFailedError,AgentcoreTimeoutErrororAgentcoreDeliveryError.agentcoreSessionErrorMapper. It restores an AgentCore error to its class, and passes any other error tocallerErrorMapper. So a job error that leaves the handler reaches the caller with its class. A plain handler error is still aChildContextError, as before.callerErrorMapperis the SDK-error rule ofsessionErrorMapperincompute/microvm/errors.ts, moved into its own function.sessionErrorMappernow calls it. Its behavior does not change, and the MicroVM tests pass without edits.rebuildAgentcoreErroris the class lookup ofagentcoreErrorMapper, moved into its own function so both AgentCore mappers use it.agentcoreSessionis exported from@aws/durable-execution-sdk-js-extras/compute/agentcore, with@publicand@experimentaltags.What this copies from
MicrovmSession.invokename, created in thecontextthat the caller passes. The handle holds no context of its own.DurablePromise.microvmErrorMapper(jobName)there,agentcoreErrorMapper(jobName)here).sessionErrorMapperthere,agentcoreSessionErrorMapperhere, with the sharedcallerErrorMapper).Decisions that the issue did not cover
invokedoes not check the job name oroptions.timeout.MicrovmSession.invokechecks both. The brief for this epic asks for no new guards. An invalid timeout fails at the callback.timeoutfield is not touched. [AgentCore session] Remove the unused session timeout #1262 removes it.invokecall, not once per session, so the session's own errors do not change.agentcore()reads it in the same place in its order.Simpler options considered (rule 2)
ChildContextError, not as its AgentCore class. The "leaves the session" tests fail.agentcoreErrorMapperas the session mapper: it turns every handler error intoAgentcoreError, which is wrong for caller code.Testing
npm testin the extras package: 613 passed, 1 skipped (34 test files passed, 1 skipped).tsc --noEmitandnpm run lintpass.src/compute/agentcore/__tests__/session.test.ts(7):invoke(a nested child context);AgentcoreJobFailedError, and the handler can then run a second job in the same session;AgentcoreJobFailedError,AgentcoreTimeoutErrorandAgentcoreDeliveryError, the same on the first run and on replay;errorTypeChildContextError. The expectation is the behavior on main. It is added so that the session mapper's fallback has a test.Closes #1235
Part of #1245
Twin: aws/aws-durable-execution-sdk-python#944