GenAgent Utilities
A Python package providing utilities for generative agent tasks, including:
- Interacting with LLM providers (OpenAI, Anthropic).
- Helper functions for prompt engineering and structured output.
- Basic agent memory and chat session management.
(See genagent/__init__.py for the current version)
Installation
pip install genagent
Configuration
GenAgent now supports environment variable configuration for default provider and model:
# In your .env file or environment
DEFAULT_PROVIDER=ant # or 'oai' for OpenAI
DEFAULT_MODEL=claude-3-7-sonnet-latest # or any model you prefer
OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key
Usage
from genagent import gen, Agent, ChatSession, mod_gen, modular_instructions
# --- Basic text generation ---
response = gen("Tell me a concise joke.")
print(f"Joke: {response}")
# --- Agent memory example ---
my_agent = Agent(name="MyTestAgent")
my_agent.add_memory("The capital of France is Paris.")
my_agent.add_memory("The Eiffel Tower is in Paris.")
retrieved_text = my_agent.retrieve_memories_as_text(query="What is a famous landmark in the capital of France?")
print(f"Retrieved memories based on query: {retrieved_text}")
# --- Chat session example ---
# Assuming 'my_agent' is already created and has some memories
chat_session = ChatSession(agent=my_agent, system_prompt="You are a helpful assistant. Use your memory when relevant.")
user_query = "What can you tell me about Paris based on your memory?"
assistant_response = chat_session.chat(user_query)
print(f"\nChat Session:")
print(f" User: {user_query}")
print(f" Assistant: {assistant_response}")
# --- Structured output with mod_gen ---
# 'mod_gen' helps generate structured output based on a list of instruction modules.
# Each module in the list is a dictionary that can have:
# - 'instruction': (Required) The text prompt or instruction for the LLM.
# - 'name': (Optional) If provided, the LLM's output for this instruction will be captured under this key in the result.
# Modules without a 'name' contribute to the context but aren't extracted as separate fields.
# Example modules for extracting information:
instruction_modules = [
{
"instruction": "You are analyzing a piece of text. The text is: 'GenAgent is a Python library for building applications with Large Language Models. It simplifies interactions with models like GPT and Claude, and provides tools for memory management.'"
},
{
"name": "summary",
"instruction": "Provide a brief one-sentence summary of the text."
},
{
"name": "main_features",
"instruction": "List up to three main features or capabilities mentioned."
},
{
"name": "target_audience",
"instruction": "Based on the description, who is the target audience?"
}
]
print("\nAttempting structured output with mod_gen...")
# mod_gen now uses environment defaults if not specified
structured_output = mod_gen(
modules=instruction_modules
# provider and model will use environment defaults
)
if structured_output:
print("\nStructured Output from mod_gen:")
for key, value in structured_output.items():
print(f"- {key.capitalize()}: {value}")
else:
print("\nMod_gen did not return structured output. Check for errors or try debugging.")
What's New in 0.2.1
- Parallelization: Added experiment utils
run_parallel_dict_mapandrun_parallel_dict_productfrom e chi
What's New in 0.2.0
- Modular architecture: Agent utilities moved to separate
agent_utilsmodule - Environment configuration: Default provider and model can be set via environment variables
- Improved defaults:
mod_gennow uses configured defaults instead of hardcoded values - Better code organization: Cleaner separation of concerns between LLM utilities and agent functionality
Development
To install for development (from the root of the llm-utils repository):
pip install -e .
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for genagent 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| genagent-0.4.1.tar.gz | 19.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| genagent-0.4.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 38.3 kB
Release files / genagent-0.4.1.tar.gz
| Download URL | genagent-0.4.1.tar.gz |
|---|---|
| Size | 19.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b3c75dc028ea71654cee4a22e65564bc956862f069c2f7030667d758372f273
|
|
BLAKE2b-256 checksum How to use checksums |
29bec618cc67a6efc1891696bdc72c3dcc31740a7445b18229194f447e08799f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.12
|
Release files / genagent-0.4.1-py3-none-any.whl
| Download URL | genagent-0.4.1-py3-none-any.whl |
|---|---|
| Size | 18.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
caf7bbc1c6308bfdf14f6560a10e89a3c34323e42413df751481815194802ac6
|
|
BLAKE2b-256 checksum How to use checksums |
f1ff50d2a0e9b96be16eddc65ac1ed450ae067110c4953d33551d7525139af1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.12
|