An AI agent that processes natural language commands through LLM and executes corresponding actions
Project description
🤖 Aigent-py
A powerful AI agent framework for natural language command processing using LLMs.
Aigent-py is a Python framework that enables seamless integration of natural language commands with your applications. Built on top of OpenAI's GPT models, it provides a flexible command system that translates natural language into structured actions.
✨ Features
- 🎯 Natural Language Processing: Process user commands using state-of-the-art LLMs
- 🔧 Extensible Command System: Easy-to-use decorator-based command registration
- 🎨 Customizable Prompts: Flexible system prompt management for different use cases
- 🚀 Async Support: Built with asyncio for high-performance applications
- 🛠️ Type Safety: Full type hints and Pydantic models for robust code
- 📦 Modern Python: Built for Python 3.8+ with modern best practices
🚀 Quick Start
Installation
pip install aigent-py
# or with Poetry
poetry add aigent-py
Basic Usage
from aigent_py import Agent
# Initialize the agent with custom parameters
agent = Agent(
agent_purpose="Help users manage their tasks",
base_url="https://api.openai.com/v1",
api_key="your-api-key",
model_name="gpt-3.5-turbo", # Default model
max_tokens=1000, # Maximum response length
temperature=0.7, # Controls randomness (0.0 to 1.0)
frequency_penalty=0.0, # Reduces repetition (-2.0 to 2.0)
presence_penalty=0.0 # Encourages diversity (-2.0 to 2.0)
)
# Process user input with streaming response
async def main():
async for response in agent.process_input("Create a new task called 'Write documentation'"):
print(response, end="", flush=True)
Creating Custom Commands
The command system in Aigent-py is powerful and flexible. Here's a comprehensive example showing advanced features:
from aigent_py.commands import CommandRegistry, command, VariableMetadata
# Create a command registry
registry = CommandRegistry()
@command(
registry=registry,
name="generate_wallet",
description="Generates a new cryptocurrency wallet",
explanation="Creates a secure cryptocurrency wallet with public and private keys using industry-standard encryption.",
pattern="[[GENERATE_WALLET_{user_id}]]",
variables=[
VariableMetadata(
name="user_id",
description="Unique identifier of the user requesting the wallet",
example="user123"
)
],
example_inputs=[
"Please generate me a wallet",
"Create me a new wallet",
"I need a cryptocurrency wallet"
],
# Example responses for successful operations
example_success_responses=[
{
"result": "Generated wallet with address: 0x123...",
"response": """Great news! I've generated your new cryptocurrency wallet.
Wallet Details:
✓ Address: 0x123...
✓ Status: Active and ready
Next steps:
1. Back up your credentials
2. Set up 2FA
3. You're ready to receive crypto!"""
}
],
# Example responses for error handling
example_failed_responses=[
{
"result": "Error: Network connection failed",
"response": """I couldn't generate your wallet due to network issues.
Troubleshooting steps:
1. Check your connection
2. Wait a few minutes
3. Try again
Your security wasn't compromised. Want to retry?"""
}
],
# Template for formatting successful results
result_prompt="""You are a cryptocurrency assistant presenting wallet generation results.
Format the current result in a user-friendly way.
Examples of good responses: {examples}""",
# Template for formatting errors
unsuccessful_prompt="""You are a cryptocurrency assistant handling wallet generation failures.
Explain what went wrong and provide next steps.
Examples of good responses: {examples}"""
)
def generate_wallet(user_id: str) -> str:
if user_id == "error":
raise ValueError("Wallet generation failed")
return f"Generated wallet with address: 0x{user_id}123..."
# Initialize agent with commands
agent = Agent(
agent_purpose="I am a cryptocurrency assistant that helps users manage their digital assets.",
base_url="https://api.openai.com/v1",
api_key="your-api-key",
model_name="gpt-3.5-turbo",
max_tokens=1000
)
agent.initialize_commands(registry)
# Use the agent
async def main():
async for response in agent.process_input("I need a new crypto wallet"):
print(response, end="", flush=True)
Key Features Demonstrated:
- 🎯 Rich Command Metadata: Comprehensive command description and explanation
- 📝 Example Inputs: Natural language examples for better LLM understanding
- ✨ Response Templates: Customizable success and error message formatting
- 🔄 Error Handling: Structured approach to handling and presenting errors
- 🎨 Response Examples: Pre-defined examples for consistent output formatting
- 📚 Type Hints: Full type annotations for better code maintainability
🎯 Use Cases
- 🤖 Chatbots: Build conversational interfaces that can execute actions
- 🔧 Task Automation: Create natural language interfaces for automation tasks
- 🎮 Game Commands: Implement natural language controls in games
- 🏢 Business Logic: Wrap complex business operations in simple commands
- 🔍 Search & Retrieval: Create intelligent search interfaces
Core Components
- Agent: The main class that processes user input and manages commands
- CommandRegistry: Manages the registration and execution of commands
- SystemPromptManager: Handles system prompts and their formatting
🛠️ Development
Setup Development Environment
# Clone the repository
git clone https://github.com/ChefJodlak/aigent.git
cd aigent
# Install dependencies with Poetry
poetry install
# Activate virtual environment
poetry shell
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
📬 Contact
Rafal Jodełka - @ChefJodlak - rafaljodlak@gmail.com
Project Link: https://github.com/ChefJodlak/aigent
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aigent_py-0.1.1.tar.gz.
File metadata
- Download URL: aigent_py-0.1.1.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.13.1 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27f0680301980a80e717a6d9984509fb40472cdac8451b6730ac54826297c7cd
|
|
| MD5 |
c6cdd07d512c364ec1cf0514c32b0a5f
|
|
| BLAKE2b-256 |
7d1039f176f3b7a2873873879dc4b0a25450d658f14b466fe5573bab9ce0ce98
|
File details
Details for the file aigent_py-0.1.1-py3-none-any.whl.
File metadata
- Download URL: aigent_py-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.13.1 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bd3f0b422a694b7ded5fc3dd742a72e2cbb892ea75ea99e2e290f5f212a9dff
|
|
| MD5 |
2e8a803d74075372840c92b8e67ca97c
|
|
| BLAKE2b-256 |
08ae2d625b26151393874875929820e89aa9f85da34739bac894a0fc9785419a
|