Skip to content

Allow sending custom delta events in streaming loop #1209

@markb-trustifi

Description

@markb-trustifi

Please read this first

  • Have you read the docs? yes
  • Have you searched for related issues? yes

Describe the feature

Please add support for sending custom delta events from the tool execute function when the loop runs in stream. Right now it is possible only with a hack. It will be nice to have it built-in.

const agent = new Agent({
   name: 'agent',
   tools: [tool({
      name: "mytool",
      execute: async (args, runContext, {toolCall}) => {
         const generator = getLongGenerator();
          for await (let event of result) {
              if (runContext.context.result && !runContext.context.result.cancelled) {
                    runContext.context.result._addItem({name: 'custom_event', item: event, type: 'run_item_stream_event'});
              }
          }
      }
   })]
});

const runnerOptions = {context: {}, stream: true};
const result = await run(agent, prompt, runnerOptions);
runnerOptions.context.result = result;
for await (let event of result) {
   yield event;    //combined original and custom events
}
await result.completed;

Such custom events doesn't enter into the run history. They are transparent for state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions