-
Notifications
You must be signed in to change notification settings - Fork 12
Add stage router #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add stage router #322
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Development Commands | ||
|
|
||
| ### Setup | ||
| - `make venv` - Setup development environment and install git hooks | ||
| - `make sync` - Sync dependencies with uv lock file | ||
| - `make update` - Update and lock dependencies | ||
|
|
||
| ### Code Quality | ||
| - `source .venv/bin/activate && make format` - Format code with Ruff (line length 100) | ||
| - `source .venv/bin/activate && make lint` - Run linters (Ruff + Bandit + Pyright strict mode) | ||
| - `source .venv/bin/activate && make test` - Run pytest with coverage | ||
| - `source .venv/bin/activate && pytest tests/test_specific.py` - Run single test file | ||
| - `source .venv/bin/activate && pytest tests/test_specific.py::test_function` - Run specific test | ||
|
|
||
| ### Package Management | ||
| - `uv add <package>` - Add dependency | ||
| - `uv remove <package>` - Remove dependency | ||
|
|
||
| ## Architecture Overview | ||
|
|
||
| **draive** is a Python framework for LLM applications built on haiway for state management. | ||
|
|
||
| ### Core Concepts | ||
|
|
||
| **State Management**: Uses haiway's immutable State objects and ctx for dependency injection. All configuration and context flows through state scoping. | ||
|
|
||
| **Provider Abstraction**: Unified `LMM` interface across providers (OpenAI, Anthropic, Gemini, Mistral, Ollama, Bedrock). Each provider implements standardized `LMMContext`, `LMMInput`, `LMMCompletion` types. | ||
|
|
||
| **Multimodal Content**: `MultimodalContent` handles text, images, and media uniformly. Content elements are composable and convertible across formats. | ||
|
|
||
| ### Key Components | ||
|
|
||
| **Stages**: Core processing pipeline units that transform `(LMMContext, MultimodalContent)`. Support composition, looping, caching, retry. Examples: `Stage.completion()`, `Stage.sequence()`, `Stage.loop()`. | ||
|
|
||
| **Tools**: Function calling via `@tool` decorator. `Toolbox` manages collections. Automatic schema generation and validation. | ||
|
|
||
| **Agents**: Stateful conversation entities with memory. `AgentWorkflow` for multi-agent systems. | ||
|
|
||
| **Generation APIs**: High-level interfaces like `TextGeneration`, `ModelGeneration` that handle complexity while allowing customization. | ||
|
|
||
| ### Component Flow | ||
| ``` | ||
| Generation APIs → Stages → LMM → Provider Implementation | ||
| ``` | ||
|
|
||
| ### Patterns | ||
|
|
||
| 1. **Immutable State**: All state objects are frozen | ||
| 2. **Context Scoping**: Configuration flows through execution contexts | ||
| 3. **Async First**: Fully asynchronous throughout | ||
| 4. **Composability**: Small focused components combine into complex workflows | ||
| 5. **Type Safety**: Heavy use of generics and protocols | ||
|
|
||
| ### Entry Points | ||
|
|
||
| - Simple: `TextGeneration.generate()`, `ModelGeneration.generate()` | ||
| - Tools: `@tool` decorator with `tools` parameter | ||
| - Complex: `Stage` composition and `Agent` systems | ||
| - Setup: Context managers with provider configs | ||
|
|
||
| ### Testing | ||
|
|
||
| Uses pytest with async support. Tests are in `tests/` directory. Key test patterns: | ||
| - Mock LMM responses for unit tests | ||
| - Use actual providers for integration tests | ||
| - Test both sync and async code paths |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the protocol inconsistency causing a runtime error.
The default lambda now expects a
metaparameter, but thePromptAvailabilityCheckprotocol (lines 18-19) still defines functions as taking no parameters, and theavailableproperty (line 69) calls_check_availability()with no arguments. This will cause aTypeErrorat runtime.To fix this inconsistency, you need to update both the protocol definition and the function call:
And update the
availableproperty to pass the metadata:@property def available(self) -> bool: try: - return self._check_availability() + return self._check_availability(self.declaration.meta) except Exception: return False📝 Committable suggestion
🤖 Prompt for AI Agents