4. Consumer agent¶
Reference
The reference for this topic is Consumer agent.
Needs an instruct model
The agent calls a language model, and its search an embedding model. Set
INSTRUCT_MODEL_PROVIDER, INSTRUCT_MODEL_MODEL, INSTRUCT_MODEL_API_KEY, then
EMBEDDING_MODEL_MODEL and EMBEDDING_MODEL_DIM (and the URL or region of your
provider). tdfs4ds.check_configuration() runs one prompt and one embedding and names
the setting to fix. The agent needs the documentation of module 2.
Once features are registered and documented, business users want to ask "do we have a
feature for how much an entity spends?" or "is total_amount still up to date?". The
consumer agent is the LangGraph chatbot that answers from the catalogs and the business
dictionary, in French or English.
import dataclasses
import getpass
import os
import tdfs4ds # importing it first also loads a .env file, if you have one
import teradataml as tdml
# 1. Open the Teradata session. Host and user come from the environment (TDFS4DS_TD_HOST,
# TDFS4DS_TD_USERNAME), the password from TDFS4DS_TD_PASSWORD or a prompt: nothing secret
# is written on this page.
host = os.environ["TDFS4DS_TD_HOST"]
user = os.environ["TDFS4DS_TD_USERNAME"]
password = os.environ.get("TDFS4DS_TD_PASSWORD") or getpass.getpass("Teradata password: ")
tdml.create_context(host=host, username=user, password=password)
# 2. Pick your industry. This is the ONLY line to change: retail, banking, healthcare, pharma,
# manufacturing, assembly, energy or transportation. Every name below comes from S.
S = tdfs4ds.tutorial_scenario("retail")
# 3. Connect to the feature store (created when missing) and choose a data domain. disposable=True
# records that this domain is an experiment, so the last page removes it in one call.
DATABASE = os.environ.get("TDFS4DS_TD_DATABASE") or user
tdfs4ds.connect(database=DATABASE, create_if_missing=True)
tdfs4ds.create_data_domain(f"TUTORIAL_{S.name.upper()}", disposable=True) # an experiment: removable in one call
# 4. The tutorial data: three tables written once; a second run keeps them.
try:
S = tdfs4ds.create_tutorial_data(S.name, DATABASE)
except ValueError:
S = dataclasses.replace(S, database=DATABASE)
def register_entity_features():
"""Page 1 in one call: (re)register the entity features and return the process id."""
sql = f"""
SELECT {S.entity}, COUNT(*) AS nb_events, SUM({S.amount}) AS total_amount,
AVG({S.amount}) AS avg_amount, COUNT(DISTINCT {S.partner}) AS nb_partners
FROM {S.table('events')}
GROUP BY 1"""
return tdfs4ds.upload_features(
df=None, sql_query=sql, target_view_name=f"{S.database}.{S.name}_entity_features",
entity_id=[S.entity], feature_names=["nb_events", "total_amount", "avg_amount", "nb_partners"],
replace=True, document=False, optimize_query=False, return_process_id=True)
process_id = register_entity_features()
You should see a process id. Document the process (module 2) and build the index (module 5) first, or the agent answers from the catalogs alone.
What it can answer¶
| Intent | Example question |
|---|---|
| SEARCH | "Which features describe the spending of an entity?" |
| DEFINITION | "What is total_amount?" |
| USAGE | "How do I use nb_events in a dashboard?" |
| FRESHNESS | "Is nb_events up to date?" |
| SUMMARY | "Give me an overview of this data domain." |
| LINEAGE | "Where does avg_amount come from?" |
| EXPLAIN | "How is nb_partners calculated?" |
The agent keeps a conversation memory per thread_id, so a follow-up reuses the resolved
entity, feature group and data domain.
1 · Ask a question from Python¶
from tdfs4ds.agent import consumer_agent
answer = consumer_agent("Which features do we have for the entity?", thread_id="tutorial-1")
print(answer)
answer = consumer_agent("How is nb_partners calculated?", thread_id="tutorial-1")
print(answer)
You should see a list of the four features with their meaning, then an explanation of
nb_partners (the number of distinct partners met in the events), in plain words.
2 · Launch the chatbot¶
from tdfs4ds.agent import launch_chatbot_with_index
launch_chatbot_with_index(port=7860, force_rebuild=False)
You should see a line with the address of the interface (port 7860). The call builds or refreshes the vector index from the business dictionary, then opens a Gradio interface with the chat, an agent trace panel and a visualizations panel.
Where the answers come from¶
The agent reads structured SQL first (catalog lookups, follow-up reports, SHOW VIEW)
and falls back to vector search when an exact lookup finds nothing.
Module 5 is about where that index lives.
Clean up¶
Close the interface (stop the cell, or press Ctrl+C in the terminal). Nothing else is created; the index is covered in module 5.
Learn more¶
- Consumer agent: graph flow, skill catalog, MCP integration, multi-turn memory model.
- Recipes › Launch the chatbot: minimal end-to-end notebook.
- LLM & embedding models: instruct and embedding configuration.