Skip to content

Agent

Data Structures for LLM Agent.

Task

Bases: BaseModel

Represents a single task with an instruction.

Attributes:

Name Type Description
id_ str

Identifier for task.

instruction str

The instruction for the task.

Source code in src/llm_agents_from_scratch/data_structures/agent.py
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:
        """String representation of Task."""
        return self.instruction

__str__

__str__()

String representation of Task.

Source code in src/llm_agents_from_scratch/data_structures/agent.py
def __str__(self) -> str:
    """String representation of Task."""
    return self.instruction

TaskStep

Bases: BaseModel

Represents a step within a task and its own instruction.

Attributes:

Name Type Description
id_ str

Identifier for task step.

task_id str

ID of associated task.

instruction str

The instruction for the task.

Source code in src/llm_agents_from_scratch/data_structures/agent.py
class TaskStep(BaseModel):
    """Represents a step within a task and its own instruction.

    Attributes:
        id_: Identifier for task step.
        task_id: ID of associated task.
        instruction: The instruction for the task.
    """

    id_: str = Field(default_factory=lambda: str(uuid.uuid4()))
    task_id: str
    instruction: str = Field(
        description="The instruction for this step in the task.",
    )

    def __str__(self) -> str:
        """String representation of TaskStep."""
        return self.instruction

__str__

__str__()

String representation of TaskStep.

Source code in src/llm_agents_from_scratch/data_structures/agent.py
def __str__(self) -> str:
    """String representation of TaskStep."""
    return self.instruction

TaskStepResult

Bases: BaseModel

The result of a task step execution.

Attributes:

Name Type Description
task_step_id str

The ID of the TaskStep that was executed.

content str

The content results of the execution.

Source code in src/llm_agents_from_scratch/data_structures/agent.py
class TaskStepResult(BaseModel):
    """The result of a task step execution.

    Attributes:
        task_step_id: The ID of the `TaskStep` that was executed.
        content: The content results of the execution.
    """

    task_step_id: str
    content: str

    def __str__(self) -> str:
        """String representation of TaskStepResult."""
        return self.content

__str__

__str__()

String representation of TaskStepResult.

Source code in src/llm_agents_from_scratch/data_structures/agent.py
def __str__(self) -> str:
    """String representation of TaskStepResult."""
    return self.content

TaskResult

Bases: BaseModel

The result of the task execution.

Attributes:

Name Type Description
task_id str

The ID Task that was executed.

content str

The content results of the task execution.

Source code in src/llm_agents_from_scratch/data_structures/agent.py
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
    content: str

    def __str__(self) -> str:
        """String representation of TaskResult."""
        return self.content

__str__

__str__()

String representation of TaskResult.

Source code in src/llm_agents_from_scratch/data_structures/agent.py
def __str__(self) -> str:
    """String representation of TaskResult."""
    return self.content

NextStepDecision

Bases: BaseModel

Structured output used within TaskHandler.get_next_step().

Source code in src/llm_agents_from_scratch/data_structures/agent.py
class NextStepDecision(BaseModel):
    """Structured output used within TaskHandler.get_next_step()."""

    kind: Literal["next_step", "final_result"]
    content: str = Field(
        description=(
            "If kind='next_step': describe the next tool call to make. "
            "If kind='final_result': the final answer (ONLY when task "
            "objective is fully achieved)."
        ),
    )

RejectedTaskResult

Bases: BaseModel

Human rejection feedback from the approval gate.

Added in Chapter 8. Returned by _process_loop when the operator rejects a proposed TaskResult; passed to get_next_step so it can route deterministically to a new TaskStep without consulting the LLM.

Attributes:

Name Type Description
failed_result_content str

Content of the rejected TaskResult.

feedback str

The operator's raw correction rationale.

Source code in src/llm_agents_from_scratch/data_structures/agent.py
class RejectedTaskResult(BaseModel):
    """Human rejection feedback from the approval gate.

    Added in Chapter 8. Returned by ``_process_loop`` when the operator
    rejects a proposed ``TaskResult``; passed to ``get_next_step`` so it
    can route deterministically to a new ``TaskStep`` without consulting
    the LLM.

    Attributes:
        failed_result_content: Content of the rejected ``TaskResult``.
        feedback: The operator's raw correction rationale.
    """

    failed_result_content: str
    feedback: str

ApprovalResult

Bases: BaseModel

The outcome of the end-of-loop human approval gate.

Added in Chapter 8.

Attributes:

Name Type Description
approved bool

Whether the human accepted the proposed task result.

feedback str

The human's correction rationale on rejection; empty on approval.

Source code in src/llm_agents_from_scratch/data_structures/agent.py
class ApprovalResult(BaseModel):
    """The outcome of the end-of-loop human approval gate.

    Added in Chapter 8.

    Attributes:
        approved: Whether the human accepted the proposed task result.
        feedback: The human's correction rationale on rejection; empty
            on approval.
    """

    approved: bool
    feedback: str = ""

    def __str__(self) -> str:
        """String representation of ApprovalResult."""
        if self.approved:
            return "approved"
        return f"rejected: {self.feedback}"

__str__

__str__()

String representation of ApprovalResult.

Source code in src/llm_agents_from_scratch/data_structures/agent.py
def __str__(self) -> str:
    """String representation of ApprovalResult."""
    if self.approved:
        return "approved"
    return f"rejected: {self.feedback}"