Skip to main content

No project description provided

Project description

pip install make_agents

MakeAgents

MakeAgents is a micro framework for creating LLM-powered agents. It consists of tools and a paridigm for creating agents.

Quickstart examples

Example 1: A simple conversational agent

import json
import pprint

import make_agents as ma

from pydantic import BaseModel, Field
# Define the functions the agent will use


class MessageUserArg(BaseModel):
    question: str = Field(description="Question to ask user")


@ma.llm_func
def message_user(arg: MessageUserArg):
    """Send the user a message, and get their response."""
    response = ""
    while response == "":
        response = input(arg.question).strip()
    return response


class LogNameArg(BaseModel):
    first_name: str = Field(description="User's first name")
    last_name: str = Field(description="User's last name")


@ma.llm_func
def log_name(arg: LogNameArg):
    """Log the name of the user. Only do this if you are certain."""
    return {"first_name": arg.first_name, "last_name": arg.last_name}


# Define the agent, as a graph of functions
agent_graph = {
    ma.Start: [message_user],
    message_user: [message_user, log_name],
}
display(ma.draw_graph(agent_graph))

# Initialise the message stack with a system prompt
messages_init = [
    {
        "role": "system",
        "content": "Get the first and last name of the user.",
    }
]

# Run the agent
for messages in ma.run_agent(agent_graph, messages_init):
    pprint.pprint(messages[-1], indent=2)
    print()
print(f"Retrieved user_name: {json.loads(messages[-1]['content'])}")

png

{ 'content': None,
  'function_call': { 'arguments': '{"next_function": "message_user"}',
                     'name': 'select_next_func'},
  'role': 'assistant'}

{ 'content': '{"next_function": "message_user"}',
  'name': 'select_next_func',
  'role': 'function'}

{ 'content': None,
  'function_call': { 'arguments': '{"question": "What is your first name?"}',
                     'name': 'message_user'},
  'role': 'assistant'}

{ 'content': '"Uh, well, it\'s Bill"',
  'name': 'message_user',
  'role': 'function'}

{ 'content': None,
  'function_call': { 'arguments': '{"next_function": "message_user"}',
                     'name': 'select_next_func'},
  'role': 'assistant'}

{ 'content': '{"next_function": "message_user"}',
  'name': 'select_next_func',
  'role': 'function'}

{ 'content': None,
  'function_call': { 'arguments': '{"question": "And what is your last name?"}',
                     'name': 'message_user'},
  'role': 'assistant'}

{ 'content': '"And that... would be BoBaggins"',
  'name': 'message_user',
  'role': 'function'}

{ 'content': None,
  'function_call': { 'arguments': '{"next_function": "log_name"}',
                     'name': 'select_next_func'},
  'role': 'assistant'}

{ 'content': '{"next_function": "log_name"}',
  'name': 'select_next_func',
  'role': 'function'}

{ 'content': None,
  'function_call': { 'arguments': '{\n'
                                  '"first_name": "Bill",\n'
                                  '"last_name": "BoBaggins"\n'
                                  '}',
                     'name': 'log_name'},
  'role': 'assistant'}

{ 'content': '{"first_name": "Bill", "last_name": "BoBaggins"}',
  'name': 'log_name',
  'role': 'function'}

Retrieved user_name: {'first_name': 'Bill', 'last_name': 'BoBaggins'}

Notes:

Prompting has a big impact on the performance of the agent. The llm_func function names, Pydantic models and docstrings can all be considered part of the prompt.

Dev setup

  • Clone the repo and cd into it
  • Run poetry install
  • Run poetry run pre-commit install

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

make_agents-0.1.0.tar.gz (8.7 kB view hashes)

Uploaded Source

Built Distribution

make_agents-0.1.0-py3-none-any.whl (15.1 kB view hashes)

Uploaded Python 3

Supported by

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