Skip to main content
This tutorial builds Cal-vin, an executive assistant that manages calendar appointments (via Cal.com) with employees, customers, partners, and friends. It uses the LangChain SDK for agent creation and the LangSmith platform for monitoring scheduling activities and identifying failure points, deployed on Cerebrium for seamless scaling. You can find the final version of the code here

Concepts

This app requires calendar interaction based on user instructions — an ideal use case for an agent with function (tool) calling capabilities. LangChain provides extensive agent support, and its companion tool LangSmith makes monitoring integration straightforward. A tool refers to any framework, utility, or system with defined functionality for specific use cases, such as searching Google or retrieving credit card transactions. Key LangChain concepts: ChatModel.bind_tools(): Attaches tool definitions to model calls. While providers have different tool definition formats, LangChain provides a standard interface for versatility. Accepts tool definitions as dictionaries, Pydantic classes, LangChain tools, or functions, telling the LLM how to use each tool.
AIMessage.tool_calls: An attribute on AIMessage that provides easy access to model-initiated tool calls, specifying invocations in the bind_tools format:
create_tool_calling_agent(): Unifies the above concepts to work across different provider formats, enabling easy model switching.

Setup Cal.com

Cal.com provides the calendar management foundation. Create an account here if needed. Cal serves as the source of truth — updates to time zones or working hours automatically reflect in the assistant’s responses. After creating your account:
  1. Navigate to “API keys” in the sidebar
  2. Create an API key without expiration
  3. Test the setup with a CURL request (replace these variables):
    • Username
    • API key
    • dateFrom and dateTo
Cal.com API Keys
You should get a response similar to the following:
The API key is now confirmed working and pulling calendar information. The API calls used later in this tutorial are:
  • /availability: Get your availability
  • /bookings: Book a slot

Cerebrium setup

Set up Cerebrium:
  1. Sign up here
  2. Follow installation docs here
  3. Create a starter project:
    This creates:
    • main.py: Entrypoint file
    • cerebrium.toml: Build and environment configuration
Add these pip packages to your cerebrium.toml:
Set up API keys:
  1. OpenAI GPT-3.5:
    • Sign up at OpenAI
    • Create API key here (format: sk_xxxxx)
  2. Add secrets in Cerebrium dashboard:
    • Navigate to “Secrets”
    • Add keys:
      • CAL_API_KEY: Your Cal.com API key
      • OPENAI_API_KEY: Your OpenAI API key
Cerebrium Secrets Dashboard

Agent Setup

Create two tool functions in main.py for calendar management:
  1. Get availability tool
  2. Book slot tool
The Cal.com API provides:
  • Busy time slots
  • Working hours per day
Below is the code to achieve this:
The code above:
  1. Uses @tool decorator to identify functions as LangChain tools
  2. Includes docstrings explaining functionality and required inputs
  3. Uses find_available_slots helper function to format Cal.com API responses into readable time slots ‍
The book_slot tool follows a similar pattern. It books a slot based on the selected time/day. Get the eventTypeId from the dashboard by selecting an event and grabbing the ID from the URL.
With both tools created, set up the agent in main.py:
The agent executor consists of:
  • The prompt template:
    • Defines the agent’s role, goals, and situational behavior. More precise instructions yield better results.
    • Chat History stores previous messages for conversation context.
    • Input receives new input from the end user.
  • The GPT-3.5 model serves as the LLM. Swap to Anthropic or any other provider by replacing this one line — LangChain makes this seamless.
  • Finally, these components combine with the tools to create an agent executor.

Setup Chatbot

The above code only handles a single question. A multi-turn conversation is needed to find a mutually suitable time. LangChain’s RunnableWithMessageHistory() adds tool calling capabilities and message memory. It stores previous replies in the chat_history variable (from the prompt template) and ties them to a session identifier, so the API remembers information per user/session:
Run a local test to verify everything works:
This code:
  • Defines a Pydantic object specifying the expected API parameters — user prompt and session ID.
  • The predict function (Cerebrium’s API entry point) passes the prompt and session ID to the agent and returns results. ‍
Install pip dependencies locally: pip install pydantic langchain pytz openai langchain_openai langchain-community, then run python main.py. Replace secrets with actual values when running locally. Output looks similar to: Langchain Agent Continuing the conversation eventually results in a booked slot.

Integrate Langsmith

Production monitoring is crucial for agent applications with nondeterministic workflows. LangSmith, a LangChain tool for logging, debugging, and monitoring, tracks performance and surfaces edge cases. Learn more here. Set up LangSmith monitoring:
  1. Add LangSmith to cerebrium.toml dependencies
  2. Create a free LangSmith account here
  3. Generate API key (click gear icon in bottom left)
Set the following environment variables at the top of main.py. Add the API key to Cerebrium secrets
Enable tracing by adding the @traceable decorator to functions. LangSmith automatically tracks tool invocations and OpenAI responses through function traversal. Add the decorator to the predict function and any independently instantiated functions:
LangSmith is now set up. Run python main.py and test booking an appointment. After a successful test run, data populates in LangSmith: LangSmith Runs Dashboard The Runs tab shows all runs (invocations/API requests). In 1 above, the function name appears, with input set to the Cerebrium RunID (set to “test”. The input and total latency of the run are also visible. LangSmith supports various data automations:
  • Data annotation for positive/negative case labeling
  • Dataset creation for model training
  • Online LLM-based evaluation (rudeness, topic analysis)
  • Webhook endpoint triggers
  • Additional features
Set automations by clicking the “Add rule” button above (2) and specifying conditions. Rule options include a filter, sampling rate, and action. Section 3 shows overall project metrics: run count, error rate, latency, etc. LangSmith Threads provide clean conversation tracking between agents and users. Track conversation evolution and investigate anomalies through trace analysis. Each thread links to its session ID. LangSmith Threads The Monitor tab shows agent performance metrics: trace count, LLM call success rate, time to first token, and more. LangSmith Performance Monitoring LangSmith offers straightforward integration with extensive functionality. Beyond the basics covered here, it supports the full application feedback loop: data collection/annotation → monitoring → iteration.

Deploy to Cerebrium

Deploy to Cerebrium by running cerebrium deploy. Delete the name == "main" block first (used only for local testing). After successful deployment: Cerebrium Deployment The API endpoint is now live. The agent remembers conversations as long as the session ID remains the same. Cerebrium automatically scales the application based on demand, with pay-per-use compute.
You can find the final version of the code here.

Future Enhancements

Consider implementing:
  1. Response streaming for seamless user experience
  2. Email integration for context-aware scheduling when Claire is tagged
  3. Voice capabilities for phone-based scheduling

Conclusion

LangChain, LangSmith, and Cerebrium together enable scalable agent deployment. LangChain handles LLM orchestration, tooling, and memory management. LangSmith provides production monitoring and edge case identification. Cerebrium offers pay-as-you-go scaling across hundreds or thousands of CPU/GPUs. Tag @cerebriumai in extensions to the code repository to share with the community.