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'])}")
{ '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 details)
Built Distribution
File details
Details for the file make_agents-0.1.0.tar.gz
.
File metadata
- Download URL: make_agents-0.1.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.9.18 Linux/6.2.0-1012-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d75668102b6ee95ea9d307083e3a1bba63eaae24cdebf445628c61e8b3c4c30d |
|
MD5 | 481dabf355480956b2a073c43b8d4167 |
|
BLAKE2b-256 | 4c882c9df75304c3fd9e61ad01dacce9adfdb9293e53bd890a39c9e72fc9dd88 |
File details
Details for the file make_agents-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: make_agents-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.9.18 Linux/6.2.0-1012-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d8c9ac925a3a39256880168f10a9c1b3633d074e9809171d786f007041ec4ec |
|
MD5 | d26dc6e259cdf877adec539f8bbc1538 |
|
BLAKE2b-256 | 982794cc6207186ee8a317ae8a904d47f5d41db01512147f95f3899b1f30d931 |