langchainjs icon indicating copy to clipboard operation
langchainjs copied to clipboard

Add ability to serialize / deserialize steps in AgentExecutor

Open carlosdp opened this issue 1 year ago • 0 comments

Small change that allows for asynchronous continuation of an AgentExecutor when some of the steps are longer running tasks. Example:

// CustomTool = a tool with returnDirect = true

const result = executor.call({ input }); // CustomTool returns direct with "wait", so we need to wait for a long task to finish

const serializedSteps = result.serializeSteps();

//... later

const toolResult; // contains result from CustomTool long running task

executor.deserializeSteps(serializedSteps, toolResult); // replaces the last Observation with the actual result. at the moment, CustomTool needs to be smart enough to respond with returnDirect = false now

const result = executor.call({ input }); // continue as usual, repeat

I just pulled this out of the custom executor fork I made for a project of mine, so not fully thought through, but I think this pattern makes sense.

carlosdp avatar Mar 02 '23 19:03 carlosdp