Skip to main content

Python utilities for generative agent tasks, including LLM interactions and agent memory.

Project description

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.

Version: 0.1.0 (See genagent/__init__.py for the current version)

Installation

pip install genagent

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...")
# You might need to specify a model that is good at following formatting instructions (e.g., JSON output if prompted for it)
# and ensure your LLM provider and model are correctly configured (e.g., API keys).
structured_output = mod_gen(
    modules=instruction_modules,
    provider='oai',  # or 'ant', ensure API keys are set in your environment
    model='gpt-3.5-turbo' # Example model, choose one appropriate for your provider and task
)

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.")

## Development

To install for development (from the root of the `llm-utils` repository):

```bash
pip install -e .

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

genagent-0.1.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

genagent-0.1.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: genagent-0.1.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for genagent-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a11d1606b7f68fd17b84dfa6382299bad9f799bd5c45e69b96c4a98bab0a2699
MD5 6fa08cdcfda37a0a1dc77a9a74e29a87
BLAKE2b-256 bedf037509540384226aa03122b58bebb0332494210e619eef792553bd2b2b55

See more details on using hashes here.

File details

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

File metadata

  • Download URL: genagent-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for genagent-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 34271a99267ee2a814dbd952fd68d7032a66ef47893040b1fac170ebf1245870
MD5 b0c003218a57ed9d1f379ac23bf54d9e
BLAKE2b-256 7edd2fa3159c12f08ca1170c5d7d7fff8da4b460022ac875904391363a11212f

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