← Back to list

API Orchestration with LangGraph

Project: API Orchestration Agent System Using LangGraph

REIT monero · 2025-07-14 01:09 · 0 claps · 2.8 min read
#langgraph #api-orchestration
Open on Medium ↗
Wiki topics: AGT · AI Agents

API Orchestration with LangGraph

Project: API Orchestration Agent System Using LangGraph

1. Project Objective

Example:

User Request

“Find the cheapest flight from Zagreb to Tokyo next month, check weather, and suggest hotels.”

Workflow:

User
 |
 |
Intent Analysis Agent
 |
 |
Planning Agent
 |
 |
+----------------+
|                |
Flight API Agent Weather API Agent
|                |
Hotel API Agent  |
 |
 |
Data Validation Agent
 |
 |
Response Agent
 |
 |
User

3. LangGraph Architecture

Graph Nodes

START
 |
 v
Input Analyzer
 |
 v
Task Planner
 |
 v
API Router
 |
 +----------------+
 |                |
 v                v
API Agent 1     API Agent 2
 |                |
 +----------------+
 |
Response Validator
 |
Answer Generator
 |
END

4. Agent Responsibilities

Agent 1: Intent Analysis Agent

Purpose

Understand user intent and extract requirements.

Input

User query

Output

Structured JSON.

Example:

{
 "goal":"travel planning",
 "entities":{
   "origin":"Zagreb",
   "destination":"Tokyo"
 },
 "required_actions":[
   "search_flights",
   "check_weather",
   "find_hotels"
 ]
}

Agent Prompt

You are an Intent Classification Agent.
Your task is to analyze user requests
and convert them into structured tasks.
Rules:
1. Identify user objective.
2. Extract entities.
3. Detect required APIs.
4. Identify missing information.
5. Return JSON only.
Available APIs:
- Flight Search API
- Hotel API
- Weather API
- Maps API
Output format:
{
 "intent":"",
 "entities":{},
 "tasks":[],
 "missing_information":[]
}
Do not answer the user.
Only analyze the request.

5. Task Planning Agent

Purpose

Creates execution workflow.

Input:

{
"intent":"travel planning"
}

Output:

{
"workflow":[
{
"step":1,
"agent":"flight_agent"
},
{
"step":2,
"agent":"weather_agent"
},
{
"step":3,
"agent":"hotel_agent"
}
]
}

Prompt

You are a Workflow Planning Agent.
You design execution plans for AI agents.
Your responsibilities:
- Break complex requests into steps.
- Decide execution order.
- Identify parallel tasks.
- Assign agents.
Available agents:
FlightAgent
HotelAgent
WeatherAgent
PaymentAgent
SearchAgent
Rules:
If tasks are independent:
run parallel.
If task depends on previous output:
run sequentially.
Return only JSON.

6. API Router Agent

Purpose

Select correct API.

Example:

Input:

Find hotels near Tokyo station

Output:

Hotel_Search_API

Prompt

You are an API Routing Agent.
Select the best API tool.
Available tools:
flight_search()
hotel_search()
weather_lookup()
maps_search()
payment_process()
Rules:
Choose only required APIs.
Return:
{
"tool":"",
"parameters":{}
}

7. API Execution Agent

Purpose

Calls external APIs.

Example:

response = flight_api.search(
 origin="ZAG",
 destination="NRT"
)

Agent Prompt

You are an API Execution Agent.
Your job:
1. Receive API instructions.
2. Validate parameters.
3. Execute API request.
4. Handle errors.
5. Return structured results.
Never invent API results.
If API fails:
Return:
{
"status":"error",
"reason":""
}

8. API Validation Agent

Purpose

Check API results.

Example:

Flight API returns:

{
"price":null
}

Agent detects:

Missing flight price

Prompt

You are a Data Validation Agent.
Check API responses.
Validate:
- Missing fields
- Invalid values
- Duplicate records
- Incorrect formats
Return:
{
"valid":true,
"errors":[]
}

9. Response Generation Agent

Purpose

Creates final answer.

Prompt

You are the Final Response Agent.
Combine outputs from multiple agents.
Requirements:
- Be accurate.
- Do not create fake information.
- Mention unavailable data.
- Present information clearly.
Format:
Summary
Details
Recommendations
Next Steps

10. LangGraph State Design

Example:

from typing import TypedDict
class AgentState(TypedDict):
    user_query:str
    intent:dict
    plan:list
    api_results:list
    validation:dict
    final_answer:str

11. LangGraph Workflow Code Structure

Project:

api-orchestrator/
│
├── app.py
│
├── graph/
│   ├── workflow.py
│   ├── state.py
│
├── agents/
│   ├── intent_agent.py
│   ├── planner_agent.py
│   ├── router_agent.py
│   ├── api_agent.py
│   ├── validator_agent.py
│   └── response_agent.py
│
├── tools/
│   ├── flight_api.py
│   ├── hotel_api.py
│   └── weather_api.py
│
└── requirements.txt

12. LangGraph Workflow Example

from langgraph.graph import StateGraph
workflow = StateGraph(AgentState)
workflow.add_node(
"intent",
intent_agent
)
workflow.add_node(
"planner",
planner_agent
)
workflow.add_node(
"router",
router_agent
)
workflow.add_node(
"executor",
api_agent
)
workflow.add_node(
"validator",
validator_agent
)
workflow.add_node(
"response",
response_agent
)
workflow.set_entry_point(
"intent"
)
workflow.add_edge(
"intent",
"planner"
)
workflow.add_edge(
"planner",
"router"
)
workflow.add_edge(
"router",
"executor"
)
workflow.add_edge(
"executor",
"validator"
)
workflow.add_edge(
"validator",
"response"
)
graph = workflow.compile()

13. Advanced Multi-Agent Workflow

For enterprise systems:

Supervisor Agent
                       |
        --------------------------------
        |              |               |
        v              v               v
 Research Agent   API Agent     Security Agent
        |              |               |
        --------------------------------
                       |
              Decision Agent
                       |
              Response Agent

14. Production Features

API Failure Handling

API Call
 |
Success?
 |
YES ---> Continue
NO
 |
Retry Agent
 |
Fallback API
 |
Human Approval

Memory Layer

Store:

User Preferences
Previous Requests
API History
Agent Decisions

16. Recommended Agent Prompt Template

Reusable:

SYSTEM ROLE:
You are a specialized AI agent responsible for {task}.
OBJECTIVE:
Complete {goal}.
INPUT:
{input_schema}
AVAILABLE TOOLS:
{tools}
RULES:
1. Never fabricate information.
2. Validate inputs.
3. Return structured output.
4. Explain failures.
5. Follow workflow instructions.
OUTPUT FORMAT:
JSON:
{
"status":"",
"result":"",
"errors":[]
}

메타데이터
post_id
cacfeb1796ca
slug
zanzibars-most-instagrammable-spots-capture-stunning-photos-cacfeb1796ca
url
https://medium.com/@juricavoda/zanzibars-most-instagrammable-spots-capture-stunning-photos-cacfeb1796ca
canonical_url
https://medium.com/@juricavoda/zanzibars-most-instagrammable-spots-capture-stunning-photos-cacfeb1796ca
author_url
https://medium.com/@juricavoda
status
ok
fetched_at
2026-07-14 22:02:17