-
Couldn't load subscription status.
- Fork 7
Tool Result Metadata
The ReturnToolResult class is a metadata option that instructs an AI agent to return the tool result immediately after it's called by the Language Model (LLM). This class extends the Option class and is part of the LLM Agents framework. It's designed to modify the behavior of the agent, specifically in how it handles tool execution results.
a) Immediate API Response:
use LLM\Agents\Solution\Metadata\ReturnToolResult;
use LLM\Agents\Agent\AgentAggregate;
$agent = new AgentAggregate(
agent: new Agent(key: 'api_agent', name: 'API Agent', instruction: 'Handle API requests'),
);
$agent->addMetadata(new ReturnToolResult());
$result = $executor->execute(agent: 'api_agent', prompt: 'Get user data');
echo $result->content; // Directly outputs API responseb) Data Transformation Pipeline:
use LLM\Agents\Solution\Metadata\ReturnToolResult;
class DataTransformationAgent extends AgentAggregate {
public function __construct() {
parent::__construct(
agent: new Agent(
key: 'data_transformer',
name: 'Data Transformer',
instruction: 'Transform input data',
)
);
$this->addMetadata(new ReturnToolResult());
}
}
$agent = new DataTransformationAgent();
$result = $executor->execute(agent: 'data_transformer', prompt: 'Convert CSV to JSON');
$transformedData = json_decode($result->content);c) Quick Fact Checker:
use LLM\Agents\Solution\Metadata\ReturnToolResult;
$factCheckerAgent = new AgentAggregate(
agent: new Agent(
key: 'fact_checker',
name: 'Fact Checker',
instruction: 'Verify facts using reliable sources',
)
);
$factCheckerAgent->addMetadata(new ReturnToolResult());
$result = $executor->execute(
agent: 'fact_checker',
prompt: 'Is the Earth flat?',
options: new Options(toolChoice: ToolChoice::specific('verify_fact'))
);
echo $result->content; // Outputs fact-checking result directlyd) Language Translator:
use LLM\Agents\Solution\Metadata\ReturnToolResult;
$translatorAgent = new AgentAggregate(
agent: new Agent(
key: 'translator',
name: 'Language Translator',
instruction: 'Translate text between languages',
)
);
$translatorAgent->addMetadata(new ReturnToolResult());
$result = $executor->execute(
agent: 'translator',
prompt: 'Translate "Hello, world!" to French',
options: new Options(toolChoice: ToolChoice::specific('translate'))
);
echo $result->content; // Outputs translated text directlye) Mathematical Computation:
use LLM\Agents\Solution\Metadata\ReturnToolResult;
$mathAgent = new AgentAggregate(
agent: new Agent(
key: 'math_solver',
name: 'Math Solver',
instruction: 'Solve mathematical problems',
)
);
$mathAgent->addMetadata(new ReturnToolResult());
$result = $executor->execute(
agent: 'math_solver',
prompt: 'Calculate the square root of 144',
options: new Options(toolChoice: ToolChoice::specific('calculate'))
);
echo $result->content; // Outputs calculation result directlyThe ReturnToolResult class doesn't have any configurable options itself. It's a simple metadata class that, when added to an agent, modifies its behavior to return tool results immediately. The configuration is done by adding this metadata to an agent:
use LLM\Agents\Solution\Metadata\ReturnToolResult;
$agent->addMetadata(new ReturnToolResult());a) LLM\Agents\Solution\Metadata\Option:
- Purpose: Base class for metadata options.
- Functionality: Provides a structure for defining configuration options for agents.
- Interaction:
ReturnToolResultextends this class, inheriting its basic structure and behavior.
b) LLM\Agents\Solution\SolutionMetadata:
- Purpose: Represents metadata for a solution (which can be an agent, tool, or other component).
- Functionality: Holds metadata information including type, key, and content.
- Interaction: The
Optionclass (and by extension,ReturnToolResult) is a specific type ofSolutionMetadata.
c) LLM\Agents\Solution\MetadataType:
- Purpose: Enum defining types of metadata.
- Functionality: Provides constants for different metadata types (e.g., Configuration, Memory, Prompt).
- Interaction: Used in the
Optionclass to specify the metadata type as Configuration.
d) LLM\Agents\Agent\AgentAggregate:
- Purpose: Represents an aggregation of an agent and its associated components.
- Functionality: Manages the agent's metadata, tools, and other properties.
- Interaction: The
ReturnToolResultmetadata is added to anAgentAggregateinstance to modify its behavior.
classDiagram
class SolutionMetadata {
+MetadataType type
+string key
+mixed content
}
class Option {
+__construct(string key, mixed content)
}
class ReturnToolResult {
+__construct()
}
class MetadataType {
<<enumeration>>
Configuration
Memory
Prompt
}
class AgentAggregate {
+addMetadata(SolutionMetadata metadata)
}
SolutionMetadata <|-- Option
Option <|-- ReturnToolResult
SolutionMetadata -- MetadataType
AgentAggregate --> "0..*" SolutionMetadata : contains
This class diagram illustrates the inheritance hierarchy and relationships between ReturnToolResult and its related classes. The ReturnToolResult class extends Option, which in turn extends SolutionMetadata. The AgentAggregate class can contain multiple SolutionMetadata instances, including ReturnToolResult.
The ReturnToolResult class is a simple yet powerful feature in the LLM Agents framework. It allows for immediate return of tool execution results, which can be particularly useful in scenarios where quick, direct responses are needed without further processing by the LLM. This can optimize performance and simplify the flow of data in certain use cases.