LLMAgent.Tasks (llm_agent v0.2.0)

View Source

Manages long-running tasks using AgentForge's execution capabilities.

This module provides functions for starting, monitoring, and controlling tasks that are implemented as sequences of AgentForge primitives, supporting complex flow patterns with branching, waiting conditions, and fine-grained state management.

Summary

Functions

Attempts to cancel a running task.

Gets the latest statistics for a task.

Attempts to pause a running task.

Attempts to resume a paused task.

Starts a task with the given definition and parameters.

Functions

cancel(task_id)

Attempts to cancel a running task.

Parameters

  • _task_id - The ID of the task to cancel

Returns

  • :ok - If the task was successfully cancelled
  • {:error, reason} - If the task could not be cancelled

get_stats(task_id)

Gets the latest statistics for a task.

Parameters

  • task_id - The ID of the task

Returns

A map of task statistics including stage information.

pause(task_id)

Attempts to pause a running task.

Parameters

  • _task_id - The ID of the task to pause

Returns

  • :ok - If the task was successfully paused
  • {:error, reason} - If the task could not be paused

resume(task_id)

Attempts to resume a paused task.

Parameters

  • _task_id - The ID of the task to resume

Returns

  • :ok - If the task was successfully resumed
  • {:error, reason} - If the task could not be resumed

start(task_def, params, state, opts \\ [])

Starts a task with the given definition and parameters.

Parameters

  • task_def - The task definition as a list of AgentForge primitives
  • params - Parameters for the task
  • state - The current agent state
  • opts - Additional options for task execution

Returns

A tuple containing the task ID and a task state signal.

Examples

iex> task_def = [
...>   AgentForge.Primitives.transform(fn data -> Map.put(data, :processed, true) end)
...> ]
iex> params = %{data: "test"}
iex> state = %{}
iex> {task_id, signal} = LLMAgent.Tasks.start(task_def, params, state)
iex> is_binary(task_id) and signal.type == :task_state
true