Join our Discord Server
Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Distinguished Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 700+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 9800+ members and discord server close to 2600+ members. You can follow him on Twitter(@ajeetsraina).

LangChain Quickstart: Build Your First AI Agent (Tutorial)

34 sec read

Prerequisites

  • Python 3.10+
  • An API key from a model provider (OpenAI, Anthropic, Google, etc.)
  • Install packages: pip install -U langchain langchain-openai

Step 1: Install & set your API key

uv add langchain langchain-openai
export OPENAI_API_KEY="your-api-key"

Step 2: Define a tool

from langchain.tools import tool

@tool
def check_order_status(order_id: str) -> str:
    """Look up the shipping status for an order ID."""
    return f"Order {order_id} is out for delivery."

Step 3: Create the agent

from langchain.agents import create_agent

agent = create_agent(
    model="openai:gpt-4o-mini",
    tools=[check_order_status],
    system_prompt="You are a helpful support assistant.",
)

Step 4: Run it

result = agent.invoke(
    {"messages": [{"role": "user", "content": "Where is order 4471?"}]}
)
print(result["messages"][-1].content)

Step 5 (optional): Trace with LangSmith

export LANGSMITH_TRACING="true"
export LANGSMITH_API_KEY="your-langsmith-key"

That’s the full loop: model + tools + prompt = agent. Swap the tool for a database lookup, an internal API call, or a search function, and the same pattern holds.

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Distinguished Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 700+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 9800+ members and discord server close to 2600+ members. You can follow him on Twitter(@ajeetsraina).

Kueue on Kubernetes: GPU Job Queueing and Fair-Share Quotas…

The default Kubernetes scheduler has no idea your GPUs are shared between teams. This hands-on lab uses Kueue to add job level admission, per...
Ajeet Raina
7 min read
Join our Discord Server