Development Guide
Development Guide
This guide provides detailed information for developers who want to extend, modify, or contribute to Insight Ingenious - an enterprise-grade Python library for building AI agent APIs with Microsoft Azure integrations. The libraryβs architecture supports extensive customization and debugging capabilities for enterprise development teams.
Development Environment Setup
Prerequisites
- Python 3.13 or higher
- Git
- uv for Python package management
Setting Up for Development
flowchart TD
START([Start Development Setup]) --> CLONE[Clone Repository]
CLONE --> INSTALL[Install Dependencies]
INSTALL --> HOOKS[Setup Pre-commit Hooks]
HOOKS --> INIT[Initialize Project]
INIT --> VERIFY[Verify Setup]
VERIFY --> READY([Ready for Development])
classDef start fill:#c8e6c9
classDef process fill:#e1f5fe
class START,READY start
class CLONE,INSTALL,HOOKS,INIT,VERIFY process
- Clone the repository:
git clone https://github.com/Insight-Services-APAC/ingenious.git cd ingenious
- Install dependencies and set up development environment:
uv sync --extra dev
- Set up pre-commit hooks:
uv run pre-commit install
- Initialize the project:
uv run ingen init
Project Architecture
Core Framework Structure
graph TB
subgraph "Core Framework"
API[API Layer<br/>FastAPI Routes]
CHAINLIT[Chainlit UI<br/>Web Interface]
CONFIG[Configuration<br/>Management]
DB[Database<br/>Integration]
FILES[File Storage<br/>Utilities]
MODELS[Data Models<br/>& Schemas]
SERVICES[Core Services<br/>Chat & Agents]
TEMPLATES[Templates<br/>Prompts & HTML]
UTILS[Utilities<br/>Helper Functions]
end
subgraph "Extensions"
EXT_API[Custom API<br/>Routes]
EXT_MODELS[Custom Models<br/>Data Structures]
EXT_SERVICES[Custom Agents<br/>& Services]
EXT_TEMPLATES[Custom Templates<br/>Domain Prompts]
SAMPLE_DATA[Sample Data<br/>Test Files]
TESTS[Test Harness<br/>Agent Testing]
end
subgraph "Development Tools"
PROMPT_TUNER[Prompt Tuner<br/>Testing Tool]
CLI[CLI Tools<br/>Management]
DOCS[Documentation<br/>Jekyll Site]
end
API --> EXT_API
MODELS --> EXT_MODELS
SERVICES --> EXT_SERVICES
TEMPLATES --> EXT_TEMPLATES
SERVICES --> PROMPT_TUNER
CLI --> CONFIG
DOCS --> TEMPLATES
classDef core fill:#e3f2fd
classDef extensions fill:#f1f8e9
classDef tools fill:#fff3e0
class API,CHAINLIT,CONFIG,DB,FILES,MODELS,SERVICES,TEMPLATES,UTILS core
class EXT_API,EXT_MODELS,EXT_SERVICES,EXT_TEMPLATES,SAMPLE_DATA,TESTS extensions
class PROMPT_TUNER,CLI,DOCS tools
π Directory Structure
graph LR
subgraph "π ingenious/"
CORE_API[π api/]
CORE_CHAINLIT[π¨ chainlit/]
CORE_CONFIG[βοΈ config/]
CORE_DB[ποΈ db/]
CORE_FILES[π files/]
CORE_MODELS[π models/]
CORE_SERVICES[π§ services/]
CORE_TEMPLATES[π templates/]
CORE_UTILS[π οΈ utils/]
end
subgraph "π ingenious_extensions_template/"
EXT_API[π api/]
EXT_MODELS[π models/]
EXT_SAMPLE[π sample_data/]
EXT_SERVICES[π€ services/]
EXT_TEMPLATES[π templates/]
EXT_TESTS[π§ͺ tests/]
end
subgraph "ποΈ ingenious_prompt_tuner/"
TUNER_AUTH[π auth.py]
TUNER_PROCESSOR[β‘ event_processor.py]
TUNER_PAYLOAD[π¦ payload.py]
TUNER_WRAPPER[π response_wrapper.py]
end
classDef core fill:#e3f2fd
classDef extensions fill:#f1f8e9
classDef tuner fill:#fff3e0
class CORE_API,CORE_CHAINLIT,CORE_CONFIG,CORE_DB,CORE_FILES,CORE_MODELS,CORE_SERVICES,CORE_TEMPLATES,CORE_UTILS core
class EXT_API,EXT_MODELS,EXT_SAMPLE,EXT_SERVICES,EXT_TEMPLATES,EXT_TESTS extensions
class TUNER_AUTH,TUNER_PROCESSOR,TUNER_PAYLOAD,TUNER_WRAPPER tuner
Core Components
π€ Multi-Agent Framework
The multi-agent framework is the heart of Insight Ingenious:
Interfaces
IConversationPattern
: Abstract base class for conversation patternsIConversationFlow
: Interface for implementing conversation flows
Services
multi_agent_chat_service
: Service managing agent conversations
Patterns
Conversation patterns define how agents interact:
conversation_patterns/
: Contains different conversation pattern implementationsclassification_agent/
: Pattern for classifying inputs and routing to specialized agents (API:classification-agent
)knowledge_base_agent/
: Pattern for knowledge retrieval and question answering (API:knowledge-base-agent
)sql_manipulation_agent/
: Pattern for SQL query generation and execution (API:sql-manipulation-agent
)education_expert/
: Pattern for educational content generation (pattern only, no direct API)
Flows
Conversation flows implement specific use cases:
conversation_flows/
: Contains flow implementations that use the patternsclassification_agent/
: Flow for classification and routing (API:classification-agent
)knowledge_base_agent/
: Flow for knowledge base interactions (API:knowledge-base-agent
)sql_manipulation_agent/
: Flow for SQL queries (API:sql-manipulation-agent
)
Note:
education_expert
exists as a pattern but does not have a corresponding flow implementation- Folder names use underscores for historical reasons, but API calls should use hyphens (e.g.,
classification-agent
)
Configuration System
The configuration system uses:
config.yml
: Project-specific, non-sensitive configurationprofiles.yml
: Environment-specific, sensitive configuration
Configuration is handled by:
ingenious/config/config.py
: Loads and validates configurationingenious/config/profile.py
: Manages profile configuration
Models:
ingenious/models/config.py
: Configuration data modelsingenious/models/config_ns.py
: Non-sensitive configuration modelsingenious/models/profile.py
: Profile data models
Adding New Components
Adding a New Agent
- Create a new folder in
ingenious/services/chat_services/multi_agent/agents/your_agent_name/
- Create the agent definition file:
agent.md
: Contains agent persona and system prompt
- Add task description:
tasks/task.md
: Describes the agentβs tasks
Adding a New Conversation Pattern
- Create a new folder in
ingenious/services/chat_services/multi_agent/conversation_patterns/your_pattern_name/
- Create an
__init__.py
file:from pkgutil import extend_path __path__ = extend_path(__path__, __name__)
- Create the pattern implementation:
# your_pattern_name.py import autogen import logging class ConversationPattern: def __init__(self, default_llm_config: dict, topics: list, memory_record_switch: bool, memory_path: str, thread_memory: str): # Initialize parameters async def get_conversation_response(self, input_message: str) -> [str, str]: # Implement conversation logic
Adding a New Conversation Flow
- Create a new folder in
ingenious/services/chat_services/multi_agent/conversation_flows/your_flow_name/
- Create an
__init__.py
file:from pkgutil import extend_path __path__ = extend_path(__path__, __name__)
- Create the flow implementation:
# your_flow_name.py import ingenious.config.config as config from ingenious.models.chat import ChatResponse from ingenious.services.chat_services.multi_agent.conversation_patterns.your_pattern_name.your_pattern_name import ConversationPattern class ConversationFlow: @staticmethod async def get_conversation_response(message: str, topics: list = [], thread_memory: str='', memory_record_switch = True, thread_chat_history: list = []) -> ChatResponse: # Initialize and use your conversation pattern
Adding a Custom API Route
- Create a module in
ingenious_extensions_template/api/routes/custom.py
- Implement the
Api_Routes
class:from fastapi import APIRouter, Depends, FastAPI from ingenious.models.api_routes import IApiRoutes from ingenious.models.config import Config class Api_Routes(IApiRoutes): def __init__(self, config: Config, app: FastAPI): self.config = config self.app = app self.router = APIRouter() def add_custom_routes(self): # Define your custom routes
Testing
Unit Tests
Run unit tests using pytest:
uv run pytest
Testing Agents
Use the test harness to test agent behavior:
uv run ingen test
Testing Prompts
Use the prompt tuner for interactive testing:
- Start the server:
uv run ingen serve
- Navigate to http://localhost:80/prompt-tuner (or your configured port)
- Select a prompt to test
- Provide sample inputs and evaluate responses
Debugging
Logging
Configure logging in config.yml
:
logging:
root_log_level: "DEBUG"
log_level: "DEBUG"
Logs are printed to the console and can be redirected to files.
Using the Debug Interface
When running in development mode, you can access:
- http://localhost:80/docs - API documentation (or your configured port)
- http://localhost:80/prompt-tuner - Prompt tuning interface
Common Issues
- Missing Configuration: Ensure environment variables are set correctly
- Agent Not Found: Check module naming and imports
- Pattern Registration: Ensure conversation patterns are properly registered
- API Key Issues: Verify profiles.yml contains valid API keys
Best Practices
Code Style
This project follows these conventions:
- PEP 8 for Python code style
- Use Ruff for linting and formatting
- Use type hints for better IDE support
Documentation
Document your code:
- Add docstrings to all functions and classes
- Update markdown documentation for user-facing features
- Include examples for complex functionality
Versioning
Follow semantic versioning:
- Major version: Breaking API changes
- Minor version: New features, non-breaking changes
- Patch version: Bug fixes and minor improvements
Commits
Write clear commit messages:
- Start with a verb (Add, Fix, Update, etc.)
- Keep first line under 50 characters
- Provide more detail in the body if needed
Pull Requests
Create focused pull requests:
- Address one feature or fix per PR
- Include tests for new functionality
- Update documentation
- Pass all CI checks
Development Workflow
π€ Agent Development
graph TB
subgraph "π€ Agent Development"
AGENT_MARKDOWN[π Agent Markdown Definition]
AGENT_FLOW[π IConversationFlow]
CUSTOM_AGENT[π§ Custom Agent<br/>Implementation]
end
subgraph "π Pattern Development"
PATTERN_INTERFACE[π IConversationPattern]
PATTERN_IMPL[π ConversationPattern]
CUSTOM_PATTERN[π Custom Pattern<br/>Implementation]
end
subgraph "π§ Service Integration"
CHAT_SERVICE[π¬ MultiAgentChatService]
CHAT_INTERFACE[π IChatService]
CUSTOM_SERVICE[π οΈ Custom Service<br/>Implementation]
end
subgraph "π¦ Registration System"
NAMESPACE_UTILS[π Namespace Utils]
DYNAMIC_LOADER[β‘ Dynamic Loader]
CONFIG_VALIDATION[β
Config Validation]
end
AGENT_MARKDOWN --> AGENT_FLOW
AGENT_FLOW --> CUSTOM_AGENT
CUSTOM_AGENT --> NAMESPACE_UTILS
PATTERN_INTERFACE --> PATTERN_IMPL
PATTERN_IMPL --> CUSTOM_PATTERN
CUSTOM_PATTERN --> NAMESPACE_UTILS
CHAT_INTERFACE --> CHAT_SERVICE
CHAT_SERVICE --> CUSTOM_SERVICE
CUSTOM_SERVICE --> NAMESPACE_UTILS
NAMESPACE_UTILS --> DYNAMIC_LOADER
NAMESPACE_UTILS --> CONFIG_VALIDATION
classDef interface fill:#e3f2fd
classDef base fill:#f1f8e9
classDef custom fill:#fff3e0
classDef registry fill:#fce4ec
class AGENT_FLOW,PATTERN_INTERFACE,CHAT_INTERFACE interface
class AGENT_MARKDOWN,PATTERN_IMPL,CHAT_SERVICE base
class CUSTOM_AGENT,CUSTOM_PATTERN,CUSTOM_SERVICE custom
class NAMESPACE_UTILS,DYNAMIC_LOADER,CONFIG_VALIDATION registry
π Creating a New Agent
sequenceDiagram
participant Dev as π¨βπ» Developer
participant Template as π Agent Template
participant AgentMD as π Agent Markdown
participant Registry as π Agent Registry
participant Service as π¬ Chat Service
participant Test as π§ͺ Test Suite
Dev->>Template: 1. Copy agent template
Template->>AgentMD: 2. Create agent.md file
Dev->>AgentMD: 3. Define agent properties
Note over Dev,AgentMD: - Title & Description<br/>- System Prompt<br/>- Tasks & Instructions
Dev->>Registry: 4. Register agent flow
Registry->>Service: 5. Make available to service
Dev->>Test: 6. Write unit tests
Test->>Dev: 7. Validate implementation
Dev->>Service: 8. Integration testing
Service->>Dev: 9. Deploy to environment
π Creating a Custom Conversation Pattern
flowchart TD
START([π Start Pattern Development]) --> DESIGN[π¨ Design Conversation Flow]
DESIGN --> INTERFACE[π§ Implement IConversationPattern]
INTERFACE --> LOGIC[β‘ Implement Flow Logic]
LOGIC --> VALIDATE[β
Validate Pattern]
VALIDATE --> REGISTER[π Register Pattern]
REGISTER --> TEST[π§ͺ Integration Testing]
TEST --> DEPLOY[π Deploy Pattern]
LOGIC --> SEQUENTIAL{Pattern Type?}
SEQUENTIAL -->|Sequential| SEQ_LOGIC[β‘οΈ Sequential Logic]
SEQUENTIAL -->|Parallel| PAR_LOGIC[β‘ Parallel Logic]
SEQUENTIAL -->|Conditional| COND_LOGIC[π Conditional Logic]
SEQUENTIAL -->|Custom| CUSTOM_LOGIC[π― Custom Logic]
SEQ_LOGIC --> VALIDATE
PAR_LOGIC --> VALIDATE
COND_LOGIC --> VALIDATE
CUSTOM_LOGIC --> VALIDATE
classDef start fill:#c8e6c9
classDef process fill:#e1f5fe
classDef decision fill:#fff9c4
classDef pattern fill:#f3e5f5
class START start
class DESIGN,INTERFACE,LOGIC,VALIDATE,REGISTER,TEST,DEPLOY process
class SEQUENTIAL decision
class SEQ_LOGIC,PAR_LOGIC,COND_LOGIC,CUSTOM_LOGIC pattern
π§ͺ Testing Framework
Test Architecture
graph TB
subgraph "π§ͺ Test Types"
UNIT[π¬ Unit Tests<br/>Individual Components]
INTEGRATION[π Integration Tests<br/>Component Interaction]
E2E[π End-to-End Tests<br/>Full Workflows]
PERFORMANCE[β‘ Performance Tests<br/>Load & Stress]
end
subgraph "π― Test Targets"
AGENTS[π€ Agent Testing]
PATTERNS[π Pattern Testing]
API[π API Testing]
UI[π¨ UI Testing]
end
subgraph "π οΈ Test Tools"
PYTEST[π pytest<br/>Test Framework]
MOCK[π Mock Objects<br/>Service Mocking]
FIXTURES[π Test Fixtures<br/>Sample Data]
COVERAGE[π Coverage Reports<br/>Code Coverage]
end
UNIT --> AGENTS
UNIT --> PATTERNS
INTEGRATION --> API
E2E --> UI
AGENTS --> PYTEST
PATTERNS --> PYTEST
API --> PYTEST
UI --> PYTEST
PYTEST --> MOCK
PYTEST --> FIXTURES
PYTEST --> COVERAGE
classDef tests fill:#e3f2fd
classDef targets fill:#f1f8e9
classDef tools fill:#fff3e0
class UNIT,INTEGRATION,E2E,PERFORMANCE tests
class AGENTS,PATTERNS,API,UI targets
class PYTEST,MOCK,FIXTURES,COVERAGE tools
Testing Best Practices
- π¬ Unit Testing: Test individual components in isolation
- π Integration Testing: Test component interactions
- π End-to-End Testing: Test complete user workflows
- π Coverage: Maintain >80% code coverage
- π Mocking: Mock external services and dependencies
- π Fixtures: Use consistent test data
π Deployment Pipeline
flowchart LR
subgraph "π» Development"
CODE[π¨βπ» Code Changes]
COMMIT[π Git Commit]
PUSH[π€ Git Push]
end
subgraph "π CI Pipeline"
LINT[π¨ Code Linting]
TEST[π§ͺ Run Tests]
BUILD[ποΈ Build Package]
SECURITY[π Security Scan]
end
subgraph "π¦ Staging"
DEPLOY_STAGE[π Deploy to Staging]
SMOKE_TEST[π¨ Smoke Tests]
INTEGRATION_TEST[π Integration Tests]
end
subgraph "π Production"
DEPLOY_PROD[π Deploy to Production]
MONITOR[π Monitor Health]
ROLLBACK[π Rollback if Needed]
end
CODE --> COMMIT
COMMIT --> PUSH
PUSH --> LINT
LINT --> TEST
TEST --> BUILD
BUILD --> SECURITY
SECURITY --> DEPLOY_STAGE
DEPLOY_STAGE --> SMOKE_TEST
SMOKE_TEST --> INTEGRATION_TEST
INTEGRATION_TEST --> DEPLOY_PROD
DEPLOY_PROD --> MONITOR
MONITOR --> ROLLBACK
classDef dev fill:#e8f5e8
classDef ci fill:#fff3e0
classDef staging fill:#e3f2fd
classDef prod fill:#fce4ec
class CODE,COMMIT,PUSH dev
class LINT,TEST,BUILD,SECURITY ci
class DEPLOY_STAGE,SMOKE_TEST,INTEGRATION_TEST staging
class DEPLOY_PROD,MONITOR,ROLLBACK prod
π§ Extension Development Guide
Step-by-Step Extension Creation
graph TD
START([π― Extension Idea]) --> PLAN[π Plan Extension]
PLAN --> TEMPLATE[π Copy Extension Template]
TEMPLATE --> IMPLEMENT[π§ Implement Components]
IMPLEMENT --> AGENT{Need Custom Agent?}
AGENT -->|Yes| CREATE_AGENT[π€ Create Custom Agent]
AGENT -->|No| PATTERN{Need Custom Pattern?}
CREATE_AGENT --> PATTERN
PATTERN -->|Yes| CREATE_PATTERN[π Create Custom Pattern]
PATTERN -->|No| API{Need Custom API?}
CREATE_PATTERN --> API
API -->|Yes| CREATE_API[π Create API Routes]
API -->|No| TEST_EXT[π§ͺ Test Extension]
CREATE_API --> TEST_EXT
TEST_EXT --> REGISTER[π Register Extension]
REGISTER --> DEPLOY[π Deploy Extension]
DEPLOY --> MONITOR[π Monitor Performance]
classDef start fill:#c8e6c9
classDef process fill:#e1f5fe
classDef decision fill:#fff9c4
classDef create fill:#f3e5f5
classDef end fill:#dcedc8
class START start
class PLAN,TEMPLATE,IMPLEMENT,TEST_EXT,REGISTER,DEPLOY,MONITOR process
class AGENT,PATTERN,API decision
class CREATE_AGENT,CREATE_PATTERN,CREATE_API create
π Key Development Concepts
Agent Lifecycle
stateDiagram-v2
[*] --> Initialized: Create Agent
Initialized --> Configured: Load Configuration
Configured --> Ready: Register with Service
Ready --> Processing: Receive Message
Processing --> Thinking: Analyze Input
Thinking --> Acting: Execute Tools
Acting --> Responding: Generate Response
Responding --> Ready: Send Response
Ready --> Shutdown: Service Stop
Shutdown --> [*]
Processing --> Error: Exception
Thinking --> Error: LLM Error
Acting --> Error: Tool Error
Error --> Ready: Handle Error
π Debugging and Troubleshooting
Debug Flow
flowchart TD
ISSUE([π¨ Issue Detected]) --> IDENTIFY{π Identify Type}
IDENTIFY -->|Agent Issue| AGENT_DEBUG[π€ Agent Debugging]
IDENTIFY -->|Pattern Issue| PATTERN_DEBUG[π Pattern Debugging]
IDENTIFY -->|API Issue| API_DEBUG[π API Debugging]
IDENTIFY -->|Config Issue| CONFIG_DEBUG[βοΈ Config Debugging]
AGENT_DEBUG --> LOGS[π Check Agent Logs]
PATTERN_DEBUG --> FLOW[π Trace Flow Logic]
API_DEBUG --> REQUESTS[π‘ Trace API Requests]
CONFIG_DEBUG --> SETTINGS[βοΈ Validate Settings]
LOGS --> ANALYZE[π¬ Analyze Issues]
FLOW --> ANALYZE
REQUESTS --> ANALYZE
SETTINGS --> ANALYZE
ANALYZE --> FIX[π§ Apply Fix]
FIX --> TEST[π§ͺ Test Fix]
TEST --> VERIFY[β
Verify Resolution]
VERIFY --> DONE([β
Issue Resolved])
classDef issue fill:#ffcdd2
classDef debug fill:#fff3e0
classDef process fill:#e1f5fe
classDef fix fill:#c8e6c9
class ISSUE issue
class AGENT_DEBUG,PATTERN_DEBUG,API_DEBUG,CONFIG_DEBUG debug
class LOGS,FLOW,REQUESTS,SETTINGS,ANALYZE process
class FIX,TEST,VERIFY,DONE fix
Contributing Guidelines
π€ Contribution Process
- π΄ Fork the Repository: Create your own fork
- πΏ Create Feature Branch: Use descriptive branch names
- π» Implement Changes: Follow coding standards
- π§ͺ Add Tests: Ensure proper test coverage
- π Update Documentation: Keep docs current
- π€ Submit Pull Request: Use PR template
- π Code Review: Address reviewer feedback
- π Merge: Celebrate your contribution!
π Code Style Guidelines
- π Python: Follow PEP 8 standards
- π Line Length: Maximum 88 characters
- π·οΈ Type Hints: Use type annotations
- π Docstrings: Document all public methods
- π§ͺ Tests: Write tests for new features
- π Security: Follow security best practices
Next Steps
- π Read the Architecture Guide for system design
- π§ Check the Configuration Guide for setup
- π Try the Getting Started Guide for quick setup
- π‘ Explore the API Documentation for integration
- π‘ Explore the API Documentation for integration