feat(workflow): add DSL to StateGraph compiler with strongly typed errors#1125
Open
Deepak-negi11 wants to merge 2 commits intomofa-org:mainfrom
Open
feat(workflow): add DSL to StateGraph compiler with strongly typed errors#1125Deepak-negi11 wants to merge 2 commits intomofa-org:mainfrom
Deepak-negi11 wants to merge 2 commits intomofa-org:mainfrom
Conversation
a57df6e to
0294ed2
Compare
…rors - Add DslCompiler that bridges YAML/TOML DSL to StateGraph - Replace generic DslError::Validation(String) with strongly typed variants - Add conditional routing deduplication and Command route/send builders - Fix state_graph tests and node state keys to use node identifiers - Add workflow_dsl example with real DSL compiler usage - Add state_graph_core_fixes example Fixes mofa-org#691
0294ed2 to
d81ede1
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🎯 Overview
This PR introduces the DslCompiler, bridging the gap between our declarative YAML/TOML workflow definitions and the StateGraph execution engine. It allows parsed DSLs to be natively compiled into a CompiledGraphImpl that can be invoked, streamed, or stepped through.
Additionally, this PR refactors the parser's error handling, replacing generic string-based validation errors with strongly typed thiserror variants for much better programmatic error matching and observability.
🚀 Key Changes
DslCompiler Implementation (compiler.rs)
Node Adapters: Implemented NodeFunc adapters to translate DSL nodes into executable graph nodes (PassthroughNode, DslTaskNode, DslConditionNode, DslJoinNode, DslTransformNode, DslAgentNode).
Agent Registry: Added support for resolving LlmAgent nodes against an injected HashMap registry of LLMAgent instances.
Condition Evaluation: Built a stateless JSON value comparator to handle edge routing conditions (==, >, <=, contains).
Topology Wiring: Implemented automatic graph wiring, connecting standard edges and mapping conditional branches.
Strongly Typed Errors (mod.rs & parser.rs)
Deprecated DslError::Validation(String) in favor of precise error variants.
Added specific variants for topology errors: MissingStartNode, MissingEndNode, DuplicateNodeId, InvalidEdge.
Added specific variants for execution/parsing errors: MissingAgentInRegistry, InlineAgentNotSupported, TomlToJsonConversion, MissingFileExtension, UnsupportedFileExtension.
Refactored WorkflowDslParser to utilize these new errors, cleaning up the TOML/YAML file extraction logic.
Comprehensive Testing
Added 1,000+ lines of tests verifying workflow roundtrips, conditional edge logic, transformation nodes, and proper error propagation for invalid schemas.
🔗 Related Issues
Fixes #691