“How far along is order SO-1024? Can it still ship tomorrow?”
Imagine a production supervisor entering that question into an internal assistant. The current stage comes from a production record. A credible shipping answer might also need inspection results, material availability, and a dispatch commitment. The examples in this series use synthetic data.
In this first exercise, you will run a Python function that returns three distinct results for an order lookup. You need Python 3.10 and uv. The function will later become a tool in a LangGraph workflow.
What the model sees
A language model generates output from the information it receives. The input can include the user's question, application instructions, and records fetched by your program. Instructions can tell the model to ask for an order number when it needs one. The production record supplies the current stage.
The text that a model reads and writes is broken into small units called tokens. The context window limits the amount of information available in a request. For a lookup, supplying the order number, stage, and timestamp is a practical starting point. Send the fields needed for the question before adding whole manuals or conversation histories.
Two model capabilities will matter later. Structured output lets you ask for fields such as intent=order_progress and order_id=SO-1024. Tool calling lets the model request an action such as get_order_progress with an order number. The application still validates the input and applies the current account's permissions. A field can match the schema and still contain the wrong order number. Model capabilities · Structured outputs · Tool use
Who chooses the next step?
For a production progress button, the selected order is already known. The application checks permissions, looks up the record, and formats the answer in that sequence. It can ask for a missing identifier or give a timeout message using predefined rules. A model can help phrase the reply within the same workflow.
A free-form request might ask about both production and shipping. An agent can select an authorized tool based on the question, look at the returned stage, and then request an inspection lookup if the stage is waiting for inspection. The application executes each allowed request and supplies the result. The model can use it to decide whether to make another request or finish the answer. Workflows and agents
These approaches can share an application. Keep authorization, metric calculations, and approvals in explicit program steps. Use a model where the application needs to interpret the question or choose among permitted queries.
Run the order lookup
Start in an empty directory. Initialize the project and save the example as order_demo.py. A dictionary stands in for the source of production records. A later installment will replace this lookup with a read-only PostgreSQL query.
# 用 uv 为本次练习创建 Python 3.10 项目
uv init --bare --python 3.10
# 模拟订单记录。后续会把字典查询换成只读数据库查询。
ORDERS = {"SO-1024": {"stage": "final_inspection", "status": "in_progress"}}
def get_order_progress(order_id: str | None) -> dict[str, str]:
"""读取 order_id 对应的模拟工序,返回处理状态及查到的字段。"""
# 缺少编号时先补问,查询留到用户给出完整参数以后。
if not order_id:
return {"result": "need_order_id"}
# 从业务数据取状态。查不到时返回一个独立的处理结果。
record = ORDERS.get(order_id)
if record is None:
return {"result": "not_found"}
# 将这次回答需要的业务字段交还给上层。
return {"result": "found", "order_id": order_id, **record}
# 三次调用分别覆盖正常查询、缺少订单号和查无记录。
for order_id in ("SO-1024", None, "SO-9999"):
print(get_order_progress(order_id))
# uv 会在首次运行时准备项目环境并执行示例
uv run --python 3.10 python order_demo.py
Look for found on the first line, with final_inspection and in_progress as the stage and status. The second line returns need_order_id. The third returns not_found. Change the first order's stage to packing and rerun the program. The stage should change, and the missing and unknown identifiers should still produce the same distinct outcomes.
This gives you a small, repeatable contract for a business tool. When you add a model, you can use the same cases to check whether it supplies the correct order number and describes the result accurately.
Where the project goes from here
The next installment looks at model choice with actual tasks in mind. We will compare language comprehension, field extraction, tool selection, and table reading using a small set of questions with known answers.
The same assistant will grow to cover current operating procedures, company policies, and management reports. A potential shipping delay will bring those pieces together in one workflow, ending with an exception ticket after human confirmation. Once the exercise works with synthetic records, you can replace one tool at a time with an integration from your own project.