Skip to content
Tradebird Docs
Build a sales agentBuilding blocks

Let your agent check stock

A product sheet can tell a buyer whether an enclosure can go outdoors. To tell them whether 500 are available today, the agent needs the warehouse count. Give it a live lookup when the answer can change between two buyer conversations.

If you sell services, you can use the same approach to check the next available installation date. Give the agent read access to the schedule. Booking the slot is a separate step.

Which units are available to sell?

Ask the warehouse team what they would check before answering a buyer. Do they count every unit on the shelf, or only units still available to sell? Does the count cover one depot or all of them? May buyers see an exact number? Agree on those details before connecting the source.

Suppose your team lets buyers see the available-to-sell count for Model A at one depot. The warehouse timestamps each count. For this example, the team accepts readings up to 15 minutes old. Choose the limit with whoever owns your real stock data.

An instruction you could give your builder:

When a buyer asks how many Model A enclosures are available, read the depot’s available-to-sell count. Give the number and the time the warehouse counted it. If you can’t get a count from the last 15 minutes for that model, say the quantity needs checking. Ask operations before confirming a delivery date.

Test it with one buyer question

Ask “Can we get 500 Model A enclosures by Friday?” Change only the warehouse response between tests. These are fictional readings taken at a depot in Copenhagen.

What the source returnsWhat a buyer should learn
620 available, counted five minutes ago at 09:10620 were available at 09:10 Copenhagen time. The quantity covers 500. Freight still needs checking before anyone confirms Friday.
300 available, counted five minutes agoThe latest count is 200 short. Ask whether a split delivery would help before asking operations about dates.
620 available, counted yesterdayToday’s quantity needs checking. Reading the same record again today doesn’t make the count fresh.
The model is missing, or the warehouse is offlineThe quantity is unknown. An explicit zero would mean the warehouse found none available.

If the agent offers to check with operations, inspect the private question as well as the buyer’s reply. Operations needs the model, quantity, destination if known, and requested date. Ask a teammate and resume the conversation.

Connect a live page in Python

For a project with live pages enabled, register a read-only handler on the agent’s publication. This example expects a source binding called model_a_stock containing JSON fields model, available, and counted_at. The timestamp must include its time zone. Use a buyer-approved source and set the page and source access for the intended audience.

from datetime import UTC, datetime, timedelta
from typing import Literal

from pydantic import AwareDatetime, BaseModel, Field
from tradebird_agents.network import LivePage, LiveRead, ReadContext


class StockReading(BaseModel):
    model: Literal["A"]
    available: int = Field(strict=True, ge=0)
    counted_at: AwareDatetime


async def model_a_stock(context: ReadContext) -> LivePage:
    reading = StockReading.model_validate_json(await context.read("model_a_stock"))
    age = datetime.now(UTC) - reading.counted_at
    if age < timedelta(0) or age > timedelta(minutes=15):
        raise ValueError("No current stock count for Model A")

    stamp = reading.counted_at.isoformat()
    return LivePage(
        markdown=f"Model A: {reading.available} units available as of {stamp}.",
        observed_at=reading.counted_at,
    )


stock_read = LiveRead("model_a_stock", model_a_stock)

Pass live_reads=(stock_read,) when you create the Publication. Declare the matching knowledge binding on the agent and its access in the publication’s knowledge_access. In the publication directory, create a Markdown page with the following header and an empty body:

+++
title = "Model A stock"
kind = "live"
handler = "model_a_stock"
source_bindings = ["model_a_stock"]
cache_seconds = 0
stale_seconds = 0
+++

With both cache windows set to zero, each read has to stand on what the source returns. The handler checks the warehouse timestamp separately. Keep the missing-data instruction on the agent so it can still give a useful reply when a read fails. For a protected source, test with a buyer who lacks access as well. Their reply must keep the count private. Choose who can see an answer.