liveBook · Manning

Task

As explained in Build a Multi-Agent System (from Scratch)

A task is a framework data structure containing the identifier and instruction for a user-submitted task.

A Task is a Pydantic data structure that pairs a required instruction with an identifier. Its generated identifier links it to the TaskResult produced when an LLMAgent executes it. section 4.1 section 4.1.1

Listing 4.1 Implementing Task and TaskResult
# llm_agents_from_scratch/data_structures/agent.py
import uuid
from typing import Literal
from pydantic import BaseModel, Field
 
 
class Task(BaseModel):
    """Represents a single task with an instruction.
 
    Attributes:
        id_: Identifier for task.
        instruction: The instruction for the task.
    """
 
    id_: str = Field(default_factory=lambda: str(uuid.uuid4()))
    instruction: str
 
    def __str__(self) -> str: #A
        """String representation of Task."""
        return self.instruction
 
 
class TaskResult(BaseModel):
    """The result of the task execution.
 
    Attributes:
        task_id: The ID `Task` that was executed.
        content: The content results of the task execution.
    """
 
    task_id: str #B
    content: str
 
    def __str__(self) -> str:
        """String representation of TaskResult."""
        return self.content

Inspect the Task and TaskResult model definitions, including Task's generated identifier and string representation. section 4.1.1

Submitting a task

For a Hailstone sequence starting at 4, the instruction specifies the rules for generating the sequence. Passing the Task to LLMAgent.run() produces a TaskResult containing `4 -> 2 -> 1`. section 4.3

How Build a Multi-Agent System (from Scratch) covers it

How deep it goes
Defines Task as a Pydantic model with a generated UUID string, required instruction, and string form; links its identifier to TaskResult.
Examples
Uses a croissant-search instruction and a Hailstone-sequence instruction starting at 4.
What you can do after
Apply it via LLMAgent.run() by submitting an instruction and retrieving its TaskResult.
How it connects
Connects Task to LLMAgent.run() and to TaskResult through matching task identifiers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Multi-Agent System (from Scratch). The section links point to the parts of the book it draws on.