TinyAgent is a lightweight Python library for creating and managing conversational agents using a GPT-based model. The library provides an easy-to-use interface for building multi-turn conversations, defining system behavior, and interacting with a model API.
- Customizable Agent Configuration: Set agent names, behaviors, and system messages.
- Conversation Management: Add system, user, and assistant messages to simulate multi-turn conversations.
- Instructions and Examples: Add explicit instructions and examples to guide model responses.
- Temperature and Token Management: Fine-tune the generation behavior using temperature and token limits.
- Flexible Output Formats: Support for text and JSON object responses.
- Lightweight and Intuitive API: Designed for rapid prototyping and development.
Clone the repository and install the required dependencies.
git clone https://github.com/Masum06/TinyAgent.git
cd TinyAgent
pip install -r requirements.txtfrom tinyagent import TinyAgent
# Create an agent with a name and system behavior
agent = TinyAgent(name="TinyAgent", system="You are a helpful assistant.")# Add a system message
agent.add_system_message("Always provide concise and accurate answers.")
# Add a user message
agent.add_user_message("What is the capital of France?")# Add explicit instructions
agent.add_instruction("Respond politely and professionally.")
# Add input-output examples
agent.add_example("What is 2+2?", "4")# Adjust the temperature (creativity)
agent.set_temperature(0.7)
# Set a maximum token limit
agent.set_max_tokens(1500)
# Change the model
agent.set_model("gpt-4o")# Generate a text response
response = agent.call(prompt="Can you tell me about the Eiffel Tower?")
print(response)
# Generate a JSON response
json_response = agent.call_json(prompt="Provide details about Python programming.")
print(json_response)- Parameters:
name(str): Name of the agent.system(str): Initial system message to define the agent's behavior.
- Description: Adds a message to the conversation.
- Parameters:
message_type(str): Role of the message (system,user, orassistant).message(str): Message content.
- Description: Adds a system message to the conversation.
- Description: Adds a user message to the conversation.
- Description: Adds an instruction to guide the agent's responses.
- Description: Adds an input-output example to the conversation.
- Description: Adds data as part of the user message.
- Description: Adjusts the creativity of responses.
- Description: Sets the maximum number of tokens for responses.
- Description: Changes the underlying model used for responses.
- Description: Generates a response from the agent.
- Parameters:
prompt(str): User input or question.response_type(str): Response format (textorjson_object).
- Returns: Model-generated response (str or JSON object).
- Description: Parses a string as JSON.
- Parameters:
s(str): Input string.
- Returns: Parsed JSON object or
None.
- Description: Generates a JSON response.
- Parameters:
prompt(str): User input or question.
- Returns: Parsed JSON response.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please submit a pull request or open an issue for any bugs or feature requests.
For questions or support, feel free to reach out at m.hasan@rochester.edu.