LLM Agents library to build single-shot, react and master agents
Project description
Introduction
This repository contains a robust and flexible conversational agent system designed to process and respond to various commands and tasks. The system is built around three main types of agents: BaseAgent, ReactAgent, and MasterAgent.
BaseAgent: This is the foundational agent class that handles the basic operations such as fetching models, setting prompts, and managing agent messages and responses.
ReactAgent: This agent extends the BaseAgent and includes additional functionality for processing commands. It uses a list of tools (functions) to perform various actions based on the commands it receives.
RAG Agent: This agent extends BaseAgent and generate response based on results of semantic search from vectorstore
MasterAgent: This agent extends the ReactAgent and is designed to manage other agents. It can fetch other agents by their names and start tasks on them. It also includes a gatekeeper function that can validate user input.
The system also includes a Context class that holds the application context, which is used by the agents to maintain state and share information.
Usage
To use these agents, you need to initialize them with the appropriate parameters. Here's a basic example of how to use these agents:
from agent_system import MasterAgent, ReactAgent, BaseAgent
Initialize a BaseAgent
from analysta_llm_agents import BaseAgent
base_agent = BaseAgent(agent_prompt="your_prompt")
Initialize a ReactAgent
from analysta_llm_agents import ReactAgent
react_agent = ReactAgent(agent_prompt="your_prompt", actions=[...])
Actions
The actions for the ReactAgent are essentially a list of functions that the agent can perform based on the commands it receives. Each action is a Python function that takes certain parameters and returns a result.
Here's a basic structure of an action function:
from analysta_llm_agents.tools.tool import tool
@tool
def action_name(ctx, arg1: str, arg2: str, ...):
# Perform some operation using the arguments and context
...
# Return the result
return result
The context ctx
parameter is an instance of the Context class and is used to share information between different parts of the application. The other parameters (arg1, arg2, etc.) are the arguments required by the action.
These action functions are added to the ReactAgent during initialization:
actions = [action1, action2, ...]
react_agent = ReactAgent(agent_prompt="your_prompt", actions=actions)
When the ReactAgent receives a command, it looks for a corresponding action in its list of actions and executes it. The arguments for the action are taken from the command. If the action requires a context, the current context of the agent is passed as an argument.
Please note that the action functions should be designed to handle errors and exceptions appropriately to ensure the robustness of the agent.
Initialize a MasterAgent
from analysta_llm_agents import MasterAgent
master_agent = MasterAgent(agent_prompt="your_prompt", agents=[...])
Agents
TO DO
Start a task on the master agent
for message in master_agent.start("your_task"):
print(message)
Please note that the start method is a generator function and you need to iterate over it to get the responses.
LLM Configuration
Still in to do
Build
python3 -m pip install --upgrade build
python3 -m build
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for analysta_llm_agents-0.2.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c0827aa2678a8d17d5269535bcb8c7cd61356e60fcc38acc1a8dfd6cc8b7751 |
|
MD5 | 3e11f4ecfabdf268a72d742d6740ebd5 |
|
BLAKE2b-256 | fce32a35731a4d4a159116057a3754f412d79e662024b1771e53edfb2e3a896d |
Hashes for analysta_llm_agents-0.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9c1f9e413e75b92f37d9054f4816c980ff018a87ad814f6dcb65933ade5f17f |
|
MD5 | 78a357492512452ffd93849fc7873cc6 |
|
BLAKE2b-256 | 07796424ea8a503ec15a4f1fe522b6a8c777a78d226b91d91831d01bc0ea2eda |