Back to prompt library
Orchestrate LangGraph Workflow and Evaluate
Linked challenge: MCP Server for Enterprise Sustainability Reporting
Prompt source
testing26 lines6 sectionsNo variables1 code block
Wire together all your LangGraph nodes (DataReader, DataAnalyzer, RiskAssessor, ReportGenerator) into a cohesive workflow. Define the conditional edges to guide the flow (e.g., if risks are high, branch to a 'HumanReview' node). Instantiate and run your graph with a sample input, ensuring it produces the required JSON output for evaluation.
```python
# Build the LangGraph
workflow = StateGraph(AgentState)
workflow.add_node("data_reader", mcp_data_reader_node)
workflow.add_node("data_analyzer", data_analyzer_node)
workflow.add_node("risk_assessor", lambda state: {"risks": ["Water usage high"], "compliance_status": "FAIL"})
workflow.add_node("report_generator", report_generator_node)
workflow.set_entry_point("data_reader")
workflow.add_edge("data_reader", "data_analyzer")
workflow.add_edge("data_analyzer", "risk_assessor")
workflow.add_edge("risk_assessor", "report_generator")
workflow.add_edge("report_generator", END)
app = workflow.compile()
# Test with a sample input
initial_state = {
"data_access_request": {"mcp_token": "valid_token_123", "data_sources": []},
"sustainability_policies": ["Max water usage: 1000m3/month per factory"],
"reporting_period": "Q1 2024",
"messages": []
}
final_state = app.invoke(initial_state)
# Print the final state to inspect the generated report
import json
print(json.dumps(final_state['compliance_report'], indent=2))
```