Download the PHP package llm-agents/agents without Composer
On this page you can find all versions of the php package llm-agents/agents. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package agents
LLM Agents
LLM Agents is a powerful PHP library for building and managing Language Model (LLM) based agents. This package provides a flexible and extensible framework for creating autonomous agents that can perform complex tasks, make decisions, and interact with various tools and APIs.
There is an article on Medium where I explaind what is LLM agents: A PHP dev’s dream: An AI home that really gets you
For a complete example with sample agents and a CLI interface to interact with them, check out our sample application repository https://github.com/llm-agents-php/sample-app. This sample app demonstrates practical implementations and usage patterns of the LLM Agents library.
The package does not include any specific LLM implementation. Instead, it provides a framework for creating agents that can interact with any LLM service or API.
Features
- Flexible Agent Creation: Easily create and configure LLM-based agents with customizable behaviors and capabilities.
- Tool Integration: Seamlessly integrate various tools and APIs for agent use, enhancing their problem-solving abilities.
- Memory Management: Built-in support for agent memory, allowing agents to retain and recall information from previous interactions.
- Prompt Management: Efficient handling of prompts and instructions for guiding agent behavior.
- Extensible Architecture: Designed with extensibility in mind, allowing easy addition of new agent types, tools, and capabilities.
- Multi-Agent Support: Create systems with multiple interacting agents for complex problem-solving scenarios.
Installation
You can install the LLM Agents package via Composer:
Usage
Creating an Agent
To create an agent, you'll need to define its behavior, tools, and configuration. Here's a basic example:
Implementing a Tool
Now, let's implement the tool used by this agent:
And the input schema for the tool:
Linking Agents
LLM Agents supports creating complex systems by linking multiple agents together. This allows you to build hierarchical or collaborative agent networks. Here's how you can link one agent to another:
Creating an Agent Link
To link one agent to another, you use the AgentLink
class. Here's an example of how to modify our
SiteStatusCheckerAgent
to include a link to another agent:
In this example, we're linking a network_diagnostics_agent
. The outputSchema
parameter specifies the expected output
format from the linked agent. The output schema is used to standardize the data format that should be returned by the
linked agent.
Using a Linked Agent
We don't provide an implementation for the linked agent here, but you can use the linked agent in your agent's execution.
Here's an example of how you might call the linked agent:
And the input schema for the tool:
And just add the tool to the agent that has linked agents. When the agent is executed, it will call the linked agent if it decides to do so.
Executing an Agent
To execute an agent, you'll use the AgentExecutor
class:
This example demonstrates how to create a simple agent that can perform a specific task using a custom tool.
Agent Memory and Prompts
Agents can use memory and predefined prompts to guide their behavior:
Implementing Required Interfaces
To use the LLM Agents package, you'll need to implement the required interfaces in your project.
LLMInterface
It serves as a bridge between your application and LLM you're using, such as OpenAI, Claude, etc.
Here is an example of MessageMapper
that converts messages to the format required by the LLM API:
AgentPromptGeneratorInterface
It plays a vital role in preparing the context and instructions for an agent before it processes a user's request. It ensures that the agent has all necessary information, including its own instructions, memory, associated agents, and any relevant session context.
- System message with the agent's instruction and important rules.
- System message with the agent's memory (experiences).
- System message about associated agents (if any).
- System message with session context (if provided).
- User message with the actual prompt.
You can customize the prompt generation logic to suit your specific requirements.
Here's an example implementation of the LLM\Agents\LLM\AgentPromptGeneratorInterface
:
SchemaMapperInterface
This class is responsible for handling conversions between JSON schemas and PHP objects.
Here's an example implementation of the LLM\Agents\Tool\SchemaMapperInterface
:
ContextFactoryInterface
It provides a clean way to pass execution-specific data through the system without tightly coupling components or overly complicating method signatures.
OptionsFactoryInterface
The options is a simple key-value store that allows you to store and retrieve configuration options that can be passed to LLM clients and other components. For example, you can pass a model name, max tokens, and other configuration options to an LLM client.
Architecture
The LLM Agents package is built around several key components:
- AgentInterface: Defines the contract for all agents.
- AgentAggregate: Implements AgentInterface and aggregates an Agent instance with other Solution objects.
- Agent: Represents a single agent with its key, name, description, and instruction.
- Solution: Abstract base class for various components like Model and ToolLink.
- AgentExecutor: Responsible for executing agents and managing their interactions.
- Tool: Represents a capability that an agent can use to perform tasks.
For a visual representation of the architecture, refer to the class diagram in the documentation.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
LLM Agents is open-source software licensed under the MIT license.