A starter project for building your own LLM agent framework with streaming, function calling, and agent delegation capabilities.
- Streaming Support: Built-in streaming for both raw responses and structured content (messages and XML tags)
- Function Calling: XML-based function calling system with automatic result handling
- Agent Delegation: Built-in support for delegating tasks to specialized agents
- Artifact Management: Automatic handling of text-based artifacts and image attachments
- Chainlit Integration: Ready-to-use integration with Chainlit for a beautiful chat interface
BaseAgent
: The foundation class implementing streaming, function calling, and delegationMovieAgent
: An example implementation showing how to build specialized agentsapp.py
: A Chainlit-based chat application showcasing the framework's capabilities
- Clone the repository
- Copy
.env_sample
to.env
and fill in your API keys - Create a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows use: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Run the application:
chainlit run app.py -w
-
Streaming Response Processing:
next_response()
: Get a single streamed responsereact_to()
: Auto-handle function calls and agent delegations- Support for XML tag processing and message content separation
-
Built-in Functions:
updateArtifact
: Create or update files in the artifacts directorysaveImage
: Save images from the conversation to the artifacts directory
-
Artifact Management:
- Automatic inclusion of text-based artifacts in system context
- Support for various file types including images
- Inherit from
BaseAgent
- Define your system prompt
- Implement any custom functions
- Register with
AgentFactory
Example:
class CustomAgent(BaseAgent):
def __init__(self, name="Custom Assistant", litellm_model=None, model_kwargs=None):
super().__init__(
name=name,
system_prompt=YOUR_SYSTEM_PROMPT,
litellm_model=litellm_model,
model_kwargs=model_kwargs
)
def custom_function(self, arg1, arg2):
# Implement your function
pass
AgentFactory.register(CustomAgent)
Feel free to submit issues and enhancement requests!