Back to Prompt Library
planning
Design LangGraph Workflow for Code Refactoring
Inspect the original prompt language first, then copy or adapt it once you know how it fits your workflow.
Linked challenge: LangChain A2A Code Refactoring with OpenAI o4-mini & AutoGPT
Format
Code-aware
Lines
9
Sections
1
Linked challenge
LangChain A2A Code Refactoring with OpenAI o4-mini & AutoGPT
Prompt source
Original prompt text with formatting preserved for inspection.
9 lines
1 sections
No variables
1 code block
Your first task is to design the LangGraph workflow. Define the states, nodes (agents), and edges that will orchestrate the code refactoring process. Include at least three distinct agent roles (e.g., `CodeAnalyzer`, `RefactorProposer`, `TestGenerator`) and define the conditional logic for state transitions. Provide the initial LangGraph definition in Python, including the `StateGraph` and `add_node`/`add_edge` calls. ```python
from typing import TypedDict, Annotated, List
from langchain_core.messages import BaseMessage
from langgraph.graph import StateGraph, END # Define the agent state
class AgentState(TypedDict): code: str refactoring_suggestions: List[str] test_results: str next_action: str # Build the graph
workflow = StateGraph(AgentState) # Add your nodes (agents) and edges here...
# workflow.add_node("analyze", code_analyzer_node)
# workflow.add_edge("analyze", "propose_refactoring")
```Adaptation plan
Keep the source stable, then change the prompt in a predictable order so the next run is easier to evaluate.
Keep stable
Preserve the role framing, objective, and reporting structure so comparison runs stay coherent.
Tune next
Swap in your own domain constraints, anomaly thresholds, and examples before you branch variants.
Verify after
Check whether the prompt asks for the right evidence, confidence signal, and escalation path.