LLM Agents
Build and control AI agents with large language models
LLM Agents is a compact library for building AI agents controlled by large language models. It offers a simplified approach to agent creation, inspired by langchain, with tools for Python REPL, Google search, and Hacker News search.
LLM Agents: Streamlined AI Agent Development
Introduction
LLM Agents is a compact and powerful library designed for building AI agents controlled by large language models (LLMs). Inspired by langchain, this project aims to simplify the process of creating and understanding AI agents, making it accessible to developers and researchers alike.
Key Features
- Simplified Architecture: Built with minimal abstraction layers for easy comprehension
- Custom Tools: Includes Python REPL, Google Search, and Hacker News Search capabilities
- Flexible Integration: Easily extendable with custom tools and LLM providers
- Thought-Action-Observation Loop: Implements a cyclical decision-making process
How It Works
The LLM Agents library operates on a straightforward principle:
- Instruction: The agent receives a prompt outlining how to solve tasks using available tools.
- Tool Utilization: Custom-built components (tools) are at the agent's disposal.
- Decision Loop: The agent follows a Thought, Action, Observation cycle:
- Thought and Action are generated by the LLM
- Observations are produced by using tools (e.g., Python REPL outputs, Google search results)
- Continuous Learning: New information is appended to the prompt in each cycle, allowing the agent to adapt and refine its approach.
- Final Answer: Once sufficient information is gathered, the agent provides a conclusive response.
Getting Started
Installation
- Clone the repository
- Run
pip install -e .
in the project directory
Environment Setup
Set the following environment variables:
OPENAI_API_KEY
: For OpenAI API accessSERPAPI_API_KEY
: For Google Search functionality (if using the SerpAPI tool)
Example:
export OPENAI_API_KEY='your-api-key-here'
export SERPAPI_API_KEY='your-serpapi-key-here'
Usage
Basic usage example:
from llm_agents import Agent, ChatLLM, PythonREPLTool, HackerNewsSearchTool, SerpAPITool
agent = Agent(llm=ChatLLM(), tools=[PythonREPLTool(), SerpAPITool(), HackerNewsSearchTool()])
result = agent.run("Your question to the agent")
print(f"Final answer is {result}")
Customization
LLM Agents is designed for flexibility:
- Create custom tools to expand the agent's capabilities
- Omit tools as needed (e.g., removing SerpAPI if you don't have an API key)
- Experiment with different LLM providers or custom prompts
Benefits
- Educational Value: Gain insights into AI agent architecture and functionality
- Rapid Prototyping: Quickly build and test AI agent concepts
- Customizable: Tailor the agent to specific use cases or research needs
- Lightweight: Minimal dependencies and straightforward implementation
Conclusion
LLM Agents offers a unique opportunity to explore and experiment with AI agent development. Whether you're a researcher, developer, or AI enthusiast, this library provides a solid foundation for building intelligent, task-oriented agents powered by large language models.
Get started with LLM Agents today and unlock the potential of AI-driven problem-solving in your projects!
Cleric
Your AI SRE teammate that autonomously troubleshoots production alerts
Qodo
Quality-first AI code generation platform for writing, testing, and reviewing code
Avanzai
AI-powered investment workflow automation for asset managers
Kusho AI
AI-powered API testing agent that generates exhaustive test suites automatically