Skip to content

Instantly share code, notes, and snippets.

@larkintuckerllc
Created December 26, 2025 11:20
Show Gist options
  • Select an option

  • Save larkintuckerllc/143506af44533df88a5b64a02abb2837 to your computer and use it in GitHub Desktop.

Select an option

Save larkintuckerllc/143506af44533df88a5b64a02abb2837 to your computer and use it in GitHub Desktop.
from langchain.agents import create_agent
from langchain.messages import HumanMessage
from pydantic import BaseModel
QUESTION = HumanMessage(content="What's the capital of the Moon?")
SYSTEM_PROMPT = "You are a science fiction writer, create a capital city at the users request."
class CapitalCity(BaseModel):
name: str
location: str
vibe: str
economy: str
agent = create_agent(
model="gpt-5-nano",
response_format=CapitalCity,
system_prompt=SYSTEM_PROMPT,
)
response = agent.invoke({
"messages": [QUESTION],
})
captial_info = response["structured_response"]
capital_name =captial_info.name
capital_location = captial_info.location
print(f"{capital_name} is a city located in {capital_location}.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment