In [1]:
from dotenv import load_dotenv
load_dotenv()
Out[1]:
True
In [2]:
import os, asyncio, json
from langchain.chat_models import init_chat_model
from langchain.agents import create_agent
from langchain.messages import HumanMessage, AIMessage
from langchain.tools import tool
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.checkpoint.memory import InMemorySaver
from typing import Dict, Any
from tavily import TavilyClient
from pprint import pprint
DEEPSEEK_MODEL = "deepseek-chat"
DEEPSEEK_BASE_URL = "https://api.deepseek.com"
def deepseek_model(model: str = DEEPSEEK_MODEL, max_tokens=1000, **kwargs):
return init_chat_model(
model=model,
# DeepSeek uses LangChain's OpenAI-compatible transport.
model_provider="openai",
api_key=os.environ["DEEPSEEK_API_KEY"],
base_url=DEEPSEEK_BASE_URL,
max_tokens=max_tokens,
**kwargs,
)
In [3]:
client = MultiServerMCPClient(
{
"travel_server": {
"transport": "sse",
"url": "https://mcp.kiwi.com"
}
}
)
tools = await client.get_tools()
In [4]:
for msg in tools:
pprint(msg.name)
print()
'search-flight' 'feedback-to-devs'
In [5]:
agent = create_agent(
deepseek_model(),
tools=tools, # main purpose to use a MCP
checkpointer=InMemorySaver(),
system_prompt="You are a travel agent. No follow up questions."
)
In [12]:
config = {"configurable": {"thread_id": "1"}}
response = await agent.ainvoke(
{"messages": [HumanMessage(content="Get me a return flight from Melbourne to Changsha on Sep 1st 2026 and return on Sep 18st 2026.")]},
config
)
print(response["messages"][-1].content)
I've already searched for this route earlier! Here's a comprehensive overview of the return flight options from Melbourne to Changsha on Sep 1st, returning Sep 18th, 2026. Please note there are **no direct flights** — all have at least one layover. --- ## 🌏 Return Flights: Melbourne (MEL) → Changsha (CSX) → Melbourne (MEL) ### 💰 Best Prices | Outbound | Return | Total | Book | |---|---|---|---| | **MEL 01/09 13:00 → SIN → CSX 02/09 23:05** (36h 05m) | **CSX 18/09 07:50 → PVG → MEL 19/09 09:00** (23h 10m) | **$706** | [Book](https://on.kiwi.com/CVWloJ) | | **MEL 01/09 13:00 → SIN → CSX 02/09 23:05** (36h 05m) | **CSX 18/09 14:10 → PVG → MEL 19/09 09:00** (16h 50m) | **$708** | [Book](https://on.kiwi.com/h51AxI) | | **MEL 01/09 21:35 → SIN → CSX 02/09 23:05** (27h 30m) | **CSX 18/09 14:10 → PVG → MEL 19/09 09:00** (16h 50m) | **$774** | [Book](https://on.kiwi.com/kmmMz9) | | **MEL 01/09 20:20 → TFU → CSX 02/09 10:20** (16h 00m) | **CSX 18/09 18:10 → TFU → MEL 19/09 14:10** (18h 00m) | **$741** | [Book](https://on.kiwi.com/iMWWDI) | | **MEL 01/09 11:00 → PVG → CSX 02/09 00:25** (15h 25m) | **CSX 18/09 14:10 → PVG → MEL 19/09 09:00** (16h 50m) | **$908** | [Book](https://on.kiwi.com/psHzZT) | | **MEL 01/09 09:15 → SIN → CSX 01/09 23:05** (15h 50m) | **CSX 18/09 14:10 → PVG → MEL 19/09 09:00** (16h 50m) | **$963** | [Book](https://on.kiwi.com/zAmYKF) | ### ⚡ Shortest Travel Times | Outbound | Return | Total | Book | |---|---|---|---| | **MEL 01/09 23:45 → HKG → CSX 02/09 11:05** (13h 20m) | **CSX 18/09 14:10 → PVG → MEL 19/09 09:00** (16h 50m) | **$1,048** | [Book](https://on.kiwi.com/vMZsQz) | | **MEL 01/09 11:00 → PVG → CSX 02/09 00:25** (15h 25m) | **CSX 18/09 14:10 → PVG → MEL 19/09 09:00** (16h 50m) | **$908** | [Book](https://on.kiwi.com/psHzZT) | | **MEL 01/09 09:15 → SIN → CSX 01/09 23:05** (15h 50m) | **CSX 18/09 14:10 → PVG → MEL 19/09 09:00** (16h 50m) | **$963** | [Book](https://on.kiwi.com/zAmYKF) | | **MEL 01/09 20:20 → TFU → CSX 02/09 10:20** (16h 00m) | **CSX 18/09 18:10 → TFU → MEL 19/09 14:10** (18h 00m) | **$741** | [Book](https://on.kiwi.com/iMWWDI) | ### 🏆 My Top Picks | Recommendation | Route | Price | Why | |---|---|---|---| | **🥇 Best Overall Value** | **MEL → PVG → CSX** + **CSX → PVG → MEL** | **$908** | Great balance of price (15h outbound, 16h 50m return) — both via Shanghai | | **🥇 Cheapest** | **MEL → SIN → CSX** + **CSX → PVG → MEL** | **$706** | Cheapest total, but long outbound layover | | **🥇 Shortest Trip** | **MEL → HKG → CSX** + **CSX → PVG → MEL** | **$1,048** | Fastest outbound at only 13h 20m via Hong Kong | | **🥇 Chengdu Route** | **MEL → TFU → CSX** + **CSX → TFU → MEL** | **$741** | Good price, both ways via Chengdu — consistent route | > **Fun fact about Changsha:** Changsha is home to **Orange Island (Júzi Zhōu)** — a massive island in the Xiang River that features a giant young Mao Zedong statue! The island gets its name from the plentiful orange trees that grow there. 🍊 Have a fantastic trip to Changsha! Let me know if you'd like to book any of these options! ✈️🎉
In [ ]: