From d63b2cf9713f1ae84eff499a31d9d9aef5b0f05c Mon Sep 17 00:00:00 2001 From: Jesse Drelick Date: Thu, 15 Aug 2024 23:53:18 -0400 Subject: [PATCH] job events --- README.md | 45 ------------------------------------------- lib/agens/job.ex | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 0453977..02b63b0 100644 --- a/README.md +++ b/README.md @@ -44,51 +44,6 @@ See the [Documentation]() for more information. ### Example See `/examples/simple-job.exs` to see how Servings, Agents and Jobs come together to create a cohesive multi-agent workflow. -### Events -Agens emits a handful events that can be used by the caller via `handle_info/3` for ui, pubsub, logging, persistence and other side-effects. - -#### Job -```elixir -{:job_started, job.name} -``` - -Emitted when a Job has been started - -```elixir -{:job_ended, job.name, :completed | {:error, error}} -``` - -Emitted when a Job has ended, whether it has ended due to completion or error - -#### Step -```elixir -{:step_started, {job.name, step_index}, message.input} -``` -Emitted when a Step has started. Includes the input data provided to the Step, whether from the user or the previous Step. - -```elixir -{:step_result, {job.name, step_index}, message.result} -``` -Emitted when a result has been returned from the Serving. Includes the Serving result, which will either be provided to the Tool (if applicable), conditions (if applicable) or the next Step of the Job. - -#### Tool -The following events are only emitted if the Agent has a Tool specified in `Agens.Agent.Config`: - -```elixir -{:tool_started, {job.name, step_index}, message.result} -``` -Emitted when a Tool is about to be called. `message.result` here is the Serving result, and will be overriden by the value returned from the Tool prior to final output. - -```elixir -{:tool_raw, {job.name, step_index}, message.raw} -``` -Emitted after completing the Tool function call. It provides the raw result of the tool, prior to any post-processing. - -```elixir -{:tool_result, {job.name, step_index}, message.result} -``` -Emitted after completing post-processing of the raw Tool result. This is the final result of the Tool and this value will be provided to either conditions or the next step of the Job. - ### Prompting Agens provides a variety of different ways to customize the final prompt sent to the LM/Serving. Each entity has a configurable field for customizing the final prompt, whereas `nil` values will omit it from the final prompt entirely. This approach provides significant flexibility for crafting detailed prompts. diff --git a/lib/agens/job.ex b/lib/agens/job.ex index d2a04e3..6d689ba 100644 --- a/lib/agens/job.ex +++ b/lib/agens/job.ex @@ -5,6 +5,56 @@ defmodule Agens.Job do An `Agens.Job` is mainly a sequence of steps, defined with the `Agens.Job.Step` struct, used to create advanced multi-agent workflows. Conditions can be used in order to route to different steps based on a result, or can be used to end the Job. + + ### Events + Agens emits several events that can be handled by the caller using `handle_info/3` for purposes such as UI updates, pubsub, logging, persistence and other side effects. + + #### Job + ```elixir + {:job_started, job.name} + ``` + + Emitted when a job has started. + + ```elixir + {:job_ended, job.name, :completed | {:error, error}} + ``` + + Emitted when a job has ended, either due to completion or an error. + + #### Step + ```elixir + {:step_started, {job.name, step_index}, message.input} + ``` + + Emitted when a step has started. Includes the input data provided to the step, whether from the user or a previous step. + + ```elixir + {:step_result, {job.name, step_index}, message.result} + ``` + + Emitted when a result has been returned from the Serving. Includes the Serving result, which will be passed to the Tool (if applicable), conditions (if applicable), or the next step of the job. + + #### Tool + The following events are emitted only if the Agent has a Tool specified in `Agens.Agent.Config`: + + ```elixir + {:tool_started, {job.name, step_index}, message.result} + ``` + + Emitted when a Tool is about to be called. `message.result` here is the Serving result, which will be overriden by the value returned from the Tool prior to final output. + + ```elixir + {:tool_raw, {job.name, step_index}, message.raw} + ``` + + Emitted after completing the Tool function call. It provides the raw result of the Tool before any post-processing. + + ```elixir + {:tool_result, {job.name, step_index}, message.result} + ``` + + Emitted after post-processing of the raw Tool result. This is the final result of the Tool, which will be passed to conditions or the next step of the job. """ defmodule Step do