Skip to content

Commit 191ee3f

Browse files
committed
initial demo workflow
1 parent 3adb56d commit 191ee3f

File tree

8 files changed

+199
-26
lines changed

8 files changed

+199
-26
lines changed

.vscode/settings.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,18 @@
3636
],
3737
"python.testing.unittestEnabled": false,
3838
"python.testing.pytestEnabled": true,
39+
"python.testing.pytestUseCoverage": false,
3940
"editor.formatOnSave": true,
4041
"editor.codeActionsOnSave": {
4142
"source.fixAll.ruff": "explicit",
4243
"source.organizeImports.ruff": "explicit"
4344
},
44-
"python.defaultInterpreterPath": ".venv_workflows/bin/python"
45+
"python.defaultInterpreterPath": ".venv_workflows/bin/python",
46+
"python.testing.unittestArgs": [
47+
"-v",
48+
"-s",
49+
"./tests",
50+
"-p",
51+
"test_*.py"
52+
]
4553
}

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@ VENV = .venv_workflows/bin
55
PYTHON = $(VENV)/python
66
PIP = $(VENV)/pip
77

8-
.PHONY: help install test lint format docs clean run coverage
8+
.PHONY: help install test lint format docs clean run coverage recreate-venv
99

1010
help: ## Show this help message
1111
@echo "Available commands:"
1212
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " %-15s %s\n", $$1, $$2}'
1313

14+
recreate-venv: ## Completely recreate the virtual environment
15+
rm -rf .venv_workflows
16+
python3 -m venv .venv_workflows
17+
$(PIP) install --upgrade pip
18+
$(PIP) install -e .[dev]
19+
$(PIP) install -e .
20+
1421
install: ## Install dependencies
1522
$(PIP) install -e .[dev]
23+
$(PIP) install -e .
1624

1725
test: ## Run tests
1826
$(PYTHON) -m pytest

code_workflow_example.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Example: Creating a multi-step workflow for writing code.
4+
"""
5+
6+
from pathlib import Path
7+
8+
from mcp_workflows.builder import WorkflowBuilder
9+
10+
# Define task prompts (you can put these in separate .md files)
11+
requirements_md = """# Requirements Analysis
12+
13+
- Gather all functional requirements
14+
- Identify constraints and edge cases
15+
- Clarify input/output specifications
16+
- Note dependencies and prerequisites"""
17+
18+
design_md = """# Design Phase
19+
20+
- Architect the solution structure
21+
- Plan algorithms and data flow
22+
- Define interfaces and modules
23+
- Consider error handling"""
24+
25+
implementation_md = """# Code Implementation
26+
27+
- Write clean, readable code
28+
- Follow language best practices
29+
- Add meaningful comments
30+
- Handle exceptions properly"""
31+
32+
testing_md = """# Testing and Review
33+
34+
- Write unit tests for key functions
35+
- Test edge cases and error conditions
36+
- Review code for bugs and optimization
37+
- Suggest improvements"""
38+
39+
def create_code_writing_workflow():
40+
"""Create a multi-step workflow for writing code."""
41+
42+
builder = (
43+
WorkflowBuilder.start()
44+
.with_goal("Write production-ready code for the specified task")
45+
.memory("code_memory.md")
46+
)
47+
48+
# Register tasks
49+
builder.register_task("requirements", text=requirements_md)
50+
builder.register_task("design", text=design_md)
51+
builder.register_task("implement", text=implementation_md)
52+
builder.register_task("test", text=testing_md)
53+
54+
# Add steps in sequence
55+
builder.add_step(
56+
"Gather Requirements",
57+
doc="Collect and analyze all requirements for the coding task",
58+
uses=["requirements"],
59+
)
60+
61+
builder.add_step(
62+
"Design Solution",
63+
doc="Plan the architecture and approach for implementation",
64+
uses=["requirements", "design"],
65+
)
66+
67+
builder.add_step(
68+
"Implement Code",
69+
doc="Write the actual code following the design plan",
70+
uses=["design", "implement"],
71+
)
72+
73+
builder.add_step(
74+
"Test and Review",
75+
doc="Test the code, review for quality, and suggest improvements",
76+
uses=["implement", "test"],
77+
)
78+
79+
return builder
80+
81+
if __name__ == "__main__":
82+
# Create and emit the workflow
83+
builder = create_code_writing_workflow()
84+
output_path = Path("workflows/code_workflow.yaml")
85+
builder.emit_yaml(output_path)
86+
87+
print(f"Multi-step code writing workflow created: {output_path}")
88+
print("\nYou can run it with:")
89+
print(f"python -m mcp_workflows.main --goal 'Write a Python function to sort a list' --out {output_path} --memory code_memory.md --run")

memory.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Demo Plan: Demo Plan :: synthesized response

pyproject.toml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,4 @@ omit = [
9898
[tool.coverage.report]
9999
exclude_lines = [
100100
"pragma: no cover",
101-
"def __repr__",
102-
"if self.debug:",
103-
"if settings.DEBUG",
104-
"raise AssertionError",
105-
"raise NotImplementedError",
106-
"if 0:",
107-
"if __name__ == \"__main__\":",
108-
"class .*\\bProtocol\\):",
109-
"@(abc\\.)?abstractmethod",
110101
]

tests/conftest.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,10 @@
22

33
from __future__ import annotations
44

5-
import pytest
6-
from pathlib import Path
75
import sys
6+
from pathlib import Path
87

98
PROJECT_ROOT = Path(__file__).resolve().parents[1]
109
SRC_PATH = PROJECT_ROOT / "src"
1110
if str(SRC_PATH) not in sys.path:
1211
sys.path.insert(0, str(SRC_PATH))
13-
14-
15-
@pytest.hookimpl
16-
def pytest_addoption(parser: pytest.Parser) -> None:
17-
"""Register coverage related arguments so test runs succeed without pytest-cov."""
18-
19-
parser.addoption("--cov", action="append", default=[], help="No-op coverage option")
20-
parser.addoption(
21-
"--cov-report",
22-
action="append",
23-
default=[],
24-
help="No-op coverage report option",
25-
)

workflows/code_workflow.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
goal: Write production-ready code for the specified task
2+
memory_file: code_memory.md
3+
tasks:
4+
- id: requirements
5+
text: '# Requirements Analysis
6+
7+
8+
- Gather all functional requirements
9+
10+
- Identify constraints and edge cases
11+
12+
- Clarify input/output specifications
13+
14+
- Note dependencies and prerequisites'
15+
- id: design
16+
text: '# Design Phase
17+
18+
19+
- Architect the solution structure
20+
21+
- Plan algorithms and data flow
22+
23+
- Define interfaces and modules
24+
25+
- Consider error handling'
26+
- id: implement
27+
text: '# Code Implementation
28+
29+
30+
- Write clean, readable code
31+
32+
- Follow language best practices
33+
34+
- Add meaningful comments
35+
36+
- Handle exceptions properly'
37+
- id: test
38+
text: '# Testing and Review
39+
40+
41+
- Write unit tests for key functions
42+
43+
- Test edge cases and error conditions
44+
45+
- Review code for bugs and optimization
46+
47+
- Suggest improvements'
48+
steps:
49+
- id: 1
50+
name: Gather Requirements
51+
kind: llm
52+
doc: Collect and analyze all requirements for the coding task
53+
uses:
54+
- requirements
55+
- id: 2
56+
name: Design Solution
57+
kind: llm
58+
doc: Plan the architecture and approach for implementation
59+
uses:
60+
- requirements
61+
- design
62+
- id: 3
63+
name: Implement Code
64+
kind: llm
65+
doc: Write the actual code following the design plan
66+
uses:
67+
- design
68+
- implement
69+
- id: 4
70+
name: Test and Review
71+
kind: llm
72+
doc: Test the code, review for quality, and suggest improvements
73+
uses:
74+
- implement
75+
- test

workflows/demo.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
goal: Sketch a sample workflow
2+
memory_file: memory.md
3+
tasks:
4+
- id: normalize
5+
file: tasks/normalize.md
6+
- id: quality_gate
7+
file: tasks/quality_gate.md
8+
steps:
9+
- id: 1
10+
name: Demo Plan
11+
kind: llm
12+
doc: Collect requirements and outline the work to perform.
13+
uses:
14+
- normalize
15+
- quality_gate

0 commit comments

Comments
 (0)