-
-
Notifications
You must be signed in to change notification settings - Fork 97
Development
See installation page for detailed instructions.
- All values must be set in your environment or a
.envfile before running AI Runner. - Be careful not to share sensitive tokens or API keys publicly.
- See Settings documentation for available environment variables
CRITICAL: The top-level docs/ directory in the main repository is DEPRECATED and git-ignored.
Documentation Location:
-
ALL documentation MUST be written in the wiki repository:
~/Projects/airunner.wiki - Never create
.mdfiles in the main repository'sdocs/folder - they will be ignored by git - Component-level
README.mdfiles withinsrc/airunner/components/*/are acceptable for internal documentation
Examples:
- ✅ Update
~/Projects/airunner.wiki/Architecture.md(feature documentation) - ✅ Create
src/airunner/components/llm/README.md(component-level internal docs) - ❌ Create
docs/new_feature.md(WRONG - git-ignored)
The use of AI tools to develop AI Runner is encouraged.
Here are some recommendations and guidelines.
- Try to keep full agent development limited to things like widgets, tests, styles
- Point your agent at existing widgets, tell your agent to use that as a reference while creating a new widget and provide detailed instructions
- Do some manual testing to ensure everything works as expected
- Your code must still be formatted correctly and follow other expected development standards
- Agents tend to fail on large features that span multiple modules - although code assistants will be helpful while editing things like the model manager classes, agents will struggle.
- AI Runner cannot as of yet program itself, but this would be an interesting area to explore.
- Join the Discord server and share some of the things you create and the prompts and techniques you used to create them
- Clone the repository:
git clone https://github.com/Capsize-Games/airunner.git cd airunner - Install dependencies:
pip install -r requirements.txt
- Set up environment variables in a
.envfile or export them directly:export AI_RUNNER_DATABASE_URL="sqlite:///path/to/database.db" export AIRUNNER_LOG_LEVEL="DEBUG"
Use the following command to start AI Runner in development mode:
python src/airunner/app.pyCRITICAL: The top-level tests/ directory is DEPRECATED and should NOT be used.
Test File Location:
- Test files MUST live in component-specific
tests/directories - Each component has its own
tests/subdirectory within the component folder - Test files follow the naming convention:
test_<module_name>.py
Examples:
- ✅
src/airunner/components/llm/tests/test_llm_manager.py - ✅
src/airunner/components/model_management/tests/test_model_resource_manager.py - ❌
tests/test_llm_manager.py(WRONG - deprecated location)
Run all unit tests:
pytest src/Run tests for a specific component:
pytest src/airunner/components/llm/tests/Run a specific test file:
pytest src/airunner/components/llm/tests/test_llm_manager.py- Use spaces for indentation
- Follow PEP 8 guidelines for Python code.
- Use
blackfor code formatting:black .- Check for linting issues with
flake8: Note: This one is optional, but recommended.
flake8 src/airunner
- Check for linting issues with
If you're using VSCode add this to the settings:
{
"black-formatter.args": ["--line-length", "79"],
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.rulers": [
{
"column": 72,
"color": "#222"
},
{
"column": 79,
"color": "#888"
},
]
}
}- Fork the repository and create a feature branch.
- Ensure all tests pass before submitting a pull request.
- Include detailed commit messages and documentation for new features.
AI Runner uses a mode-based routing system that automatically directs queries to specialized agents:
- Author Mode 🖋️ - Writing, documentation, content creation
- Code Mode 💻 - Programming, debugging, code review
- Research Mode 🔍 - Information gathering, fact-checking
- QA Mode ❓ - Question answering, explanations
- General Mode ⚙️ - Fallback for multi-domain tasks
Quick Start:
from airunner.components.llm.managers.workflow_manager import WorkflowManager
# Enable mode routing
manager = WorkflowManager(use_mode_routing=True)
response = manager.process("Write a function to parse JSON")
# Automatically routed to CODE modeDocumentation:
- Mode-Based Architecture - Complete architecture guide
- Mode-Based Architecture Examples - Usage examples and patterns
- Trajectory Evaluation Guide - Monitor agent performance
To create a new specialized agent:
-
Define State Schema:
from typing import TypedDict, Annotated from langchain_core.messages import BaseMessage from langgraph.graph.message import add_messages class MyAgentState(TypedDict): messages: Annotated[list[BaseMessage], add_messages] custom_field: str
-
Create Agent Class:
from airunner.components.llm.agents.base_agent import BaseAgent class MyAgent(BaseAgent): def __init__(self, chat_model, tools=None): super().__init__( state_schema=MyAgentState, chat_model=chat_model, tools=tools or [] )
-
Add Tests:
- Create
src/airunner/components/llm/agents/tests/test_my_agent.py - Test agent initialization, compilation, and execution
- Test trajectory and tool usage
- Create
-
Register in Router:
- Update
mode_router.pyto include new mode - Add routing logic in
parent_graph_builder.py
- Update
Unit Tests:
# Test specific agent
pytest src/airunner/components/llm/agents/tests/test_author_agent.py
# Test all agents
pytest src/airunner/components/llm/agents/tests/ -v
# Test with trajectory evaluation
pytest src/airunner/components/llm/evaluators/tests/ -vIntegration Tests:
# Test mode routing
pytest src/airunner/components/llm/managers/tests/test_e2e_mode_routing.py
# Test parent router
pytest src/airunner/components/llm/managers/tests/test_parent_graph_builder.pyTrajectory Evaluation:
from airunner.components.llm.evaluators.utils.trajectory_tracking import track_trajectory_sync
from airunner.components.llm.evaluators.utils.trajectory_evaluator import trajectory_tool_usage
# Track agent execution
trajectory = track_trajectory_sync(
graph=agent.compile(),
inputs={"messages": [...]},
expected_nodes=["agent", "tools", "response"]
)
# Validate tool usage
tools_used = trajectory_tool_usage(trajectory, expected_tools=["my_tool"])
assert tools_used["used_expected"]Creating New Tools:
-
Define Tool Function:
from langchain_core.tools import tool from airunner.enums import ToolCategory @tool def my_custom_tool(param: str) -> str: """Tool description for LLM. Args: param: Parameter description Returns: Result description """ return f"Result: {param}" # Set category metadata my_custom_tool.category = ToolCategory.CODE # or AUTHOR, RESEARCH, QA
-
Register Tool:
- Add to appropriate file in
src/airunner/components/llm/tools/ - Export from
__init__.py - Tool automatically available to agents in matching category
- Add to appropriate file in
-
Test Tool:
def test_my_custom_tool(): result = my_custom_tool.invoke({"param": "test"}) assert "Result: test" in result
Tool Categories:
-
Mode-Specific:
AUTHOR,CODE,RESEARCH,QA -
Cross-Mode:
CHAT,IMAGE,FILE,MATH,SYSTEM, etc.
If you make changes to the build files, be sure to test them locally before doing a PR. For this you can use the act tool to run the GitHub actions locally.
- Install act
- Create a github personal access token
- Add the personal access token to a
.secretsfile in the root of the project. The file should look like this:CR_PAT=ghp_xxxxxxxx1234567890abcdefg
- Run the build action locally:
act push --secret-file .secrets --verbose
AI Runner supports internationalization (i18n) using the Qt framework. The translation files are located in ./src/airunner/translations/. The main translation file is english.ts, which contains the English translations. You can create additional translation files for other languages by using the pyside6-linguist tool.
-
Update translation file:
pyside6-lupdate ./src/airunner/ -ts src/airunner/translations/english.ts
-
Edit translation file:
pyside6-linguist ./src/airunner/translations/english.ts
-
Generate translation files:
pyside6-lrelease ./src/airunner/translations/english.ts -qm ./src/airunner/translations/english.qm