Skip to content

InvokeCodeInterpreter

Source: src/AWS/BedrockAgentCore/InvokeCodeInterpreter.ts

Executes a tool (e.g. executeCode) inside a code interpreter session. The response carries a result stream.

Bind a CodeInterpreter inside a function runtime and call it with a session id obtained from StartCodeInterpreterSession. Provide AgentCore.InvokeCodeInterpreterHttp on the Function effect to implement the binding.

// init
const invoke = yield* AgentCore.InvokeCodeInterpreter(interpreter);
// runtime (inside the handler, with an open session)
const result = yield* invoke({
sessionId: session.sessionId,
name: "executeCode",
arguments: { language: "python", code: "print(21 * 2)" },
});
const chunks = yield* Stream.runCollect(result.stream);