Prompt Builder
Library for building prompts and agents with LLMs.
Installation
From PyPI:
pip install promptbuilder
From source:
git clone https://github.com/kapulkin/promptbuilder.git
cd promptbuilder
pip install -e .
Features
- Prompt templates with variables and content tags
- Structured output with TypeScript-like schema definition
- LLM client with native structured output support and caching option
- Integration with multiple LLM providers through aisuite
- Agents with routing based on tools
- Tools as agent for flexibility and scalability
Quick Start
Basic Prompt Usage
from promptbuilder.llm_client import LLMClient
from promptbuilder.prompt_builder import PromptBuilder
# Build prompt template
prompt_template = PromptBuilder() \
.text("What is the capital of ").variable("country").text("?") \
.build()
# Use with LLM
llm_client = LLMClient(model="your-model", api_key="your-api-key")
response = llm_client.from_text(
prompt_template.render(country="France")
)
print(response)
Using Agents
from typing import List
from pydantic import BaseModel, Field
from promptbuilder.agent.agent import AgentRouter
from promptbuilder.agent.context import Context, InMemoryDialogHistory
from promptbuilder.agent.message import Message
from promptbuilder.llm_client import LLMClient
# Define tool arguments
class AddTodoArgs(BaseModel):
item: TodoItem = Field(..., description="Todo item to add")
# Create custom context
class TodoItem(BaseModel):
description: str = Field(..., description="Description of the todo item")
class TodoListContext(Context[InMemoryDialogHistory]):
todos: List[TodoItem] = []
# Create agent with tools
class TodoListAgent(AgentRouter[InMemoryDialogHistory, TodoListContext]):
def __init__(self, llm_client: LLMClient, context: TodoListContext):
super().__init__(llm_client=llm_client, context=context)
llm_client = LLMClient(model="your-model", api_key="your-api-key")
agent = TodoListAgent(llm_client=llm_client, context=TodoListContext())
@agent.tool(description="Add a new todo item to the list", args_model=AddTodoArgs)
async def add_todo(message: Message, args: AddTodoArgs, context: TodoListContext) -> str:
context.todos.append(args.item)
return f"Added todo item: {args.item.description}"
# Use the agent
async def main():
response = await agent(Message(role="user", content="Add a todo: Buy groceries"))
print(response)
See the examples directory for more detailed examples, including a complete todo list manager.
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a pull request.
Metadata
Release files for promptbuilder 0.5.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| promptbuilder-0.5.5.tar.gz | 54.8 kB | Without provenance | Details for promptbuilder-0.5.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| promptbuilder-0.5.5-py3-none-any.whl | Python 3 | none | any | Details for promptbuilder-0.5.5-py3-none-any.whl |
Total release size: 110.0 kB
Release files / promptbuilder-0.5.5.tar.gz
| Download URL | promptbuilder-0.5.5.tar.gz |
|---|---|
| Size | 54.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cbb773e181adb43d958034dfea0c9f7786527cd7c6c317b89ae28ba8f2bbb277
|
|
BLAKE2b-256 checksum How to use checksums |
20a1d152a2a00097ecb389df0e324ad74bad224f46b9304b686b0edb135971a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / promptbuilder-0.5.5-py3-none-any.whl
| Download URL | promptbuilder-0.5.5-py3-none-any.whl |
|---|---|
| Size | 55.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
705a88d24428f13cc25c0797ab26a6b16bef1817fbdab10c6f255ba3363efa03
|
|
BLAKE2b-256 checksum How to use checksums |
c2860caca929a6f13e829f4f14dd71e044e8390642c50fb0fd510154083a98d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for promptbuilder 0.5.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.