Skip to main content

LLM Messages[] API on Steroids called "Threads" with easy Tool Execution and State Management

Project description

AgentPress: LLM Messages[] API on Steroids called "Threads" with automatic Tool Execution and simple state management.

AgentPress is a lightweight, powerful utility for kickstarting your LLM App or AI Agent. It provides a simple way to manage message threads, execute LLM calls, and automatically handle tool interactions.

Key Features

  • Thread Management: Easily create, update, and manage message threads.
  • Automatic Tool Execution: Define tools as Python classes and have them automatically called by the LLM.
  • Flexible LLM Integration: Uses LiteLLM under the hood, allowing easy switching between different LLM providers.
  • State Management: JSON-based state persistence for storing information, tool data, and runtime state.

Installation

pip install agentpress

Quick Start

  1. Set up your environment variables (API keys, etc.) in a .env file.

  2. Create a simple tool:

    from agentpress.tool import Tool, ToolResult, tool_schema
    
    class CalculatorTool(Tool):
        @tool_schema({
            "name": "add",
            "description": "Add two numbers",
            "parameters": {
                "type": "object",
                "properties": {
                    "a": {"type": "number"},
                    "b": {"type": "number"}
                },
                "required": ["a", "b"]
            }
        })
        async def add(self, a: float, b: float) -> ToolResult:
            return self.success_response(f"The sum is {a + b}")
    
  3. Use the ThreadManager to run a conversation:

    import asyncio
    from agentpress.thread_manager import ThreadManager
    
    async def main():
        manager = ThreadManager()
        manager.add_tool(CalculatorTool)
        thread_id = await manager.create_thread()
        await manager.add_message(thread_id, {"role": "user", "content": "What's 2 + 2?"})
        system_message = {"role": "system", "content": "You are a helpful assistant with calculation abilities."}
        response = await manager.run_thread(
            thread_id=thread_id,
            system_message=system_message,
            model_name="gpt-4o",
            execute_model_tool_calls=True
        )
        print("Response:", response)
    
    asyncio.run(main())
    
  4. Create an autonomous agent with multiple iterations:

    import asyncio
    from agentpress.thread_manager import ThreadManager
    from tools.files_tool import FilesTool
    
    async def run_autonomous_agent(max_iterations=5):
        thread_manager = ThreadManager()
        thread_id = await thread_manager.create_thread()
        thread_manager.add_tool(FilesTool)
    
        system_message = {"role": "system", "content": "You are a helpful assistant that can create, read, update, and delete files."}
    
        for iteration in range(max_iterations):
            print(f"Iteration {iteration + 1}/{max_iterations}")
            
            await thread_manager.add_message(thread_id, {"role": "user", "content": "Continue!"})
    
            response = await thread_manager.run_thread(
                thread_id=thread_id,
                system_message=system_message,
                model_name="anthropic/claude-3-5-sonnet-20240620",
                temperature=0.7,
                max_tokens=4096,
                tool_choice="auto",
                execute_tools_async=False,
                execute_model_tool_calls=True
            )
    
    if __name__ == "__main__":
        asyncio.run(run_autonomous_agent())
    

    This example demonstrates how to create an autonomous agent that runs for a specified number of iterations. It uses the FilesTool to interact with the file system and showcases how to control the behavior of run_thread by adjusting parameters like temperature, max_tokens, and tool_choice. The agent creates files autonomously.

Development Setup

If you want to contribute or modify the package:

  1. Clone the repository:

    git clone https://github.com/kortix-ai/agentpress
    cd agentpress
    
  2. Install Poetry (if not already installed):

    pip install poetry
    
  3. Install dependencies:

    poetry install
    

Contributing

We welcome contributions to AgentPress! Please feel free to submit issues, fork the repository and send pull requests!

License

MIT License

Built with ❤️ by Kortix AI Corp

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentpress-0.1.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentpress-0.1.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file agentpress-0.1.1.tar.gz.

File metadata

  • Download URL: agentpress-0.1.1.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for agentpress-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8638d35b9423bd6eb72f867651ff682f62ec7944492fb28a7801910e03a44d7c
MD5 24d2693211eb1ea10e00540c0aceea0f
BLAKE2b-256 b7053e6d5a02aa1c97ffc5136f311f9fb8570129687cd89e403dd90fa0a6d434

See more details on using hashes here.

File details

Details for the file agentpress-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: agentpress-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for agentpress-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d27d7ee2e29af887e97c31fd95cae1bd59498a92953f742f75bf15f42f79dbb9
MD5 55ee148985232be18729a5af93e61773
BLAKE2b-256 cd969099b53aa1637a1b53b077777fd863908162d57c921d56d6385a9d6b8d98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page