Quickstart: Interactive Agent Testing¶
Feature: 007-interactive-chat
Date: 2025-11-22
Audience: Developers implementing the chat feature
Overview¶
This quickstart provides a step-by-step guide for implementing the interactive chat command. Follow these steps in order to build the feature incrementally with continuous validation.
Prerequisites¶
- Python 3.10+ environment activated
- Dependencies installed:
poetry install - Familiarity with Semantic Kernel concepts (Kernel, ChatHistory, plugins)
- Understanding of Click CLI framework
Implementation Sequence¶
Phase 1: Core Data Models (Day 1)¶
Goal: Implement Pydantic models for chat sessions, messages, and tool execution.
Files to Create:
src/holodeck/models/chat.pysrc/holodeck/models/tool_execution.pysrc/holodeck/models/token_usage.py
Steps:
- Implement
MessageRole,SessionState,ToolStatus,ToolEventTypeenums - Implement
TokenUsagemodel with validation - Implement
ToolExecutionmodel with sanitization - Implement
Messagemodel with content validation - Implement
ChatSessionmodel with state management - Implement
ChatConfigmodel with path validation
Validation:
# Run unit tests
pytest tests/unit/models/test_chat.py -v
pytest tests/unit/models/test_tool_execution.py -v
# Type checking
mypy src/holodeck/models/chat.py
Success Criteria:
- All models pass Pydantic validation
- Field validators enforce constraints (size limits, enum values)
- Type hints pass MyPy strict checks
Phase 2: Input Validation & Sanitization (Day 1-2)¶
Goal: Implement extensible validation pipeline and output sanitization.
Files to Create:
src/holodeck/lib/validation.py
Steps:
- Define
MessageValidatorprotocol - Implement
ValidationPipelineclass - Implement built-in validators:
EmptyMessageValidatorSizeLimitValidator(~10K chars)ControlCharacterValidatorUTF8Validator- Implement
sanitize_tool_output()function (ANSI escape removal, HTML escaping)
Validation:
pytest tests/unit/lib/test_validation.py -v
# Test edge cases
pytest tests/unit/lib/test_validation.py::test_empty_message -v
pytest tests/unit/lib/test_validation.py::test_oversized_message -v
pytest tests/unit/lib/test_validation.py::test_terminal_injection -v
Success Criteria:
- Validators correctly reject invalid inputs
- Sanitization removes terminal escape sequences
- Pipeline is extensible (easy to add new validators)
Phase 3: Agent Executor (Day 2-3)¶
Goal: Implement Semantic Kernel integration for agent execution.
Files to Create:
src/holodeck/agent/__init__.pysrc/holodeck/agent/executor.py
Steps:
- Implement
AgentExecutor.__init__(): - Initialize Semantic Kernel
Kernel - Configure LLM service from
AgentConfig - Load tools/plugins
- Implement
AgentExecutor.execute_turn(): - Add user message to ChatHistory
- Invoke kernel with streaming
- Capture tool executions
- Track token usage
- Return
AgentResponse - Implement
AgentExecutor.get_history() - Implement
AgentExecutor.clear_history() - Implement
AgentExecutor.shutdown()
Validation:
# Unit tests with mocked Semantic Kernel
pytest tests/unit/agent/test_executor.py -v
# Integration test with real LLM (requires API key)
pytest tests/integration/test_agent_executor.py -v --slow
Success Criteria:
- Agent successfully initializes with valid config
- Multi-turn conversations maintain context
- Tool executions are captured and returned
- Token usage is tracked correctly
Phase 4: Session Manager (Day 3-4)¶
Goal: Implement chat session lifecycle and context management.
Files to Create:
src/holodeck/agent/session.py
Steps:
- Implement
ChatSessionManager.__init__() - Implement
ChatSessionManager.start(): - Create
ChatSessioninstance - Initialize
AgentExecutor - Set state to ACTIVE
- Implement
ChatSessionManager.process_message(): - Validate input via
ValidationPipeline - Pass to
AgentExecutor.execute_turn() - Increment message count
- Return response
- Implement
ChatSessionManager.should_warn_context_limit(): - Check if message_count >= max_messages * 0.8
- Implement
ChatSessionManager.terminate(): - Set state to TERMINATED
- Shutdown executor
Validation:
pytest tests/unit/agent/test_session.py -v
# Test context limit warnings
pytest tests/unit/agent/test_session.py::test_context_warning -v
Success Criteria:
- Session lifecycle managed correctly
- Context limit warnings triggered at 80%
- Invalid inputs rejected with clear errors
Phase 5: CLI Command (Day 4-5)¶
Goal: Implement interactive chat command interface.
Files to Create/Update:
src/holodeck/cli/commands/chat.py(NEW)src/holodeck/cli/main.py(UPDATE: register chat command)src/holodeck/cli/exceptions.py(UPDATE: add chat exceptions)
Steps:
- Implement
chat()Click command: - Define arguments and options
- Load agent configuration
- Create
ChatConfigfrom CLI options - Initialize
ChatSessionManager - Implement interactive REPL loop:
- Display welcome message
- Accept user input via
input() - Handle exit commands ('exit', 'quit')
- Handle Ctrl+C gracefully
- Implement response display:
- Standard mode:
You:/Agent:format - Verbose mode: detailed tool execution
- Context warnings when limit approached
- Implement error handling:
- Configuration errors (exit code 1)
- Initialization errors (exit code 2)
- Runtime errors (display, continue session)
- Register command in
cli/main.py
Validation:
# Unit test CLI command
pytest tests/unit/cli/commands/test_chat.py -v
# Manual testing
holodeck chat examples/conversational/agent.yaml
# Test verbose mode
holodeck chat examples/conversational/agent.yaml --verbose
Success Criteria:
- Command starts session in <1 second
- User can send messages and receive responses
- Exit commands work correctly
- Errors display helpful messages
Phase 6: Tool Execution Streaming (Day 5-6)¶
Goal: Implement real-time tool execution event streaming.
Files to Create:
src/holodeck/agent/streaming.py
Steps:
- Implement
ToolExecutionStreamclass - Implement
stream_execution()async generator: - Yield
ToolEvent(STARTED)when tool begins - Yield
ToolEvent(PROGRESS)during execution (if supported) - Yield
ToolEvent(COMPLETED)orToolEvent(FAILED)when done - Integrate with
AgentExecutor.execute_turn() - Update CLI to display events in real-time
Validation:
pytest tests/unit/agent/test_streaming.py -v
# Integration test with tool execution
pytest tests/integration/test_tool_streaming.py -v --slow
Success Criteria:
- Tool events stream in real-time (<100ms latency)
- Events display correctly in terminal
- Failed tools show clear error messages
Phase 7: OpenTelemetry Integration (Day 6-7)¶
Goal: Implement observability instrumentation.
Files to Create:
src/holodeck/lib/observability.py
Steps:
- Implement OpenTelemetry setup:
- Initialize
TracerProvider - Configure exporters (console, OTLP)
- Instrument Semantic Kernel
- Add session-level tracing:
- Create span for entire chat session
- Add session_id, agent_name attributes
- Add turn-level tracing:
- Create span for each message turn
- Track LLM calls, tool executions
- Add metrics:
- Token usage counts
- Session duration
- Tool execution counts
- Integrate with CLI
--observabilityflag
Validation:
pytest tests/unit/lib/test_observability.py -v
# Manual test with observability enabled
holodeck chat examples/conversational/agent.yaml --observability
# Verify traces in console output
Success Criteria:
- Traces exported to configured backend
- GenAI semantic attributes present
- Token usage metrics accurate
- No performance degradation
Phase 8: Error Handling & Edge Cases (Day 7)¶
Goal: Comprehensive error handling and edge case coverage.
Steps:
- Add error classes to
src/holodeck/lib/errors.py - Implement error handling in all modules
- Add edge case tests:
- Extremely long messages
- Rapid message submission
- LLM provider downtime
- Tool timeouts
- Invalid agent configurations
- Unicode edge cases
Validation:
# Run all tests including edge cases
pytest tests/ -v --cov=src/holodeck/agent --cov=src/holodeck/cli/commands/chat.py
# Coverage report
pytest --cov-report=html
open htmlcov/index.html
Success Criteria:
- All error scenarios handled gracefully
- No uncaught exceptions in normal usage
- Clear error messages for users
- 80%+ code coverage
Phase 9: Integration Testing (Day 8)¶
Goal: End-to-end integration tests with real agents.
Files to Create:
tests/integration/test_chat_integration.py
Steps:
- Create test agent configurations
- Implement integration test scenarios:
- Basic chat session
- Multi-turn conversations
- Tool execution
- Context limit warnings
- Error recovery
- Test with multiple LLM providers (OpenAI, Anthropic)
Validation:
# Run integration tests
pytest tests/integration/test_chat_integration.py -v --slow
# Test with different providers
ANTHROPIC_API_KEY=... pytest tests/integration/ -v --slow
Success Criteria:
- All user stories from spec validated
- Tests pass with real LLM providers
- Performance targets met (SC-001 through SC-007)
Phase 10: Documentation & Polish (Day 9)¶
Goal: User documentation and final polish.
Steps:
- Add docstrings to all public functions/classes
- Update README with chat command examples
- Create example agent configurations
- Run code quality checks:
make format make lint make type-check make security - Run full CI pipeline:
make ci
Validation:
# All checks must pass
make ci
# Manual smoke test
holodeck chat examples/conversational/agent.yaml
Success Criteria:
- All code quality checks pass
- Documentation complete and accurate
- Examples work out of the box
Testing Strategy¶
Unit Tests (Fast, Isolated)¶
- Mock Semantic Kernel components
- Test each class independently
- Focus on validation logic, error handling
- Run with every commit
Integration Tests (Slow, LLM-dependent)¶
- Use real LLM providers (test API keys)
- Test end-to-end workflows
- Run before PR merge
Manual Testing Checklist¶
- Start chat with valid agent config
- Send multiple messages, verify context preserved
- Trigger tool execution, verify display
- Test exit commands ('exit', 'quit', Ctrl+C)
- Test invalid inputs (empty, oversized)
- Test with invalid agent config (expect clear error)
- Test verbose mode (
--verbose) - Test observability mode (
--observability) - Test context limit warning (send 40+ messages)
- Test session stability (30-minute conversation)
Debugging Tips¶
Enable verbose logging:
export HOLODECK_LOG_LEVEL=DEBUG
holodeck chat agent.yaml --verbose
Enable OpenTelemetry console export:
holodeck chat agent.yaml --observability
Run with debugger:
# In chat.py, add breakpoint
import pdb; pdb.set_trace()
Profile performance:
python -m cProfile -o chat.prof src/holodeck/cli/main.py chat agent.yaml
python -m pstats chat.prof
Common Issues & Solutions¶
| Issue | Solution |
|---|---|
| LLM API key errors | Check .env file has correct keys |
| Import errors | Ensure all __init__.py files created |
| Type errors | Run mypy src/holodeck/agent/ to identify issues |
| Test failures | Check test fixtures in tests/fixtures/ |
| Slow tests | Use @pytest.mark.slow and skip with -m "not slow" |
Success Metrics¶
At the end of implementation, verify:
- ✅ All functional requirements (FR-001 through FR-016) implemented
- ✅ All success criteria (SC-001 through SC-007) met
- ✅ All acceptance scenarios from spec pass
- ✅ Code coverage ≥ 80%
- ✅ All CI checks pass (
make ci) - ✅ Manual testing checklist complete
- ✅ Constitution Check passes (re-evaluate post-implementation)
Next Steps After Completion¶
- Create PR with implementation
- Request code review from team
- Address review feedback
- Merge to main branch
- Tag release (v0.1.0 milestone)
- Update user documentation
- Plan P2/P3 features (session persistence, rich UI)