Build an agent with a knowledge base
Create a knowledge base, add a sample policy, and test a draft agent before publishing it.
This walkthrough uses a fictional returns policy to show how an Astra chat agent can answer from your own content. Use a test workspace and an Astra API key. For the gateway URL and the Bearer header, see the Astra API quickstart.
1. Create the knowledge base
Send POST /knowledge-bases with the JSON below. The kb_data wrapper is required. Save the new knowledge base ID for the next two steps. Create a knowledge base
{"kb_data":{"name":"Returns walkthrough"}}2. Add a policy the agent can answer from
Send POST /knowledge-bases/{dataset_id}/import/text. Replace {dataset_id} with the knowledge base ID and use this example body. Import plain text
{"title":"Sample returns policy","content":"Unopened items can be returned within 14 days of delivery."}Use List documents to confirm that the policy appears in this knowledge base. If you choose a web or file import instead, follow its job ID with Get import job status before testing the agent.
3. Create the agent with its knowledge base attached
Send POST /agents. Replace the placeholder with the same knowledge base ID and keep the agent ID from the response. Set knowledge_base_id at creation time. The agent update endpoint cannot change this field later. Create an agent
{
"name": "Returns walkthrough agent",
"knowledge_base_id": "REPLACE_WITH_KNOWLEDGE_BASE_UUID",
"instructions": "Answer returns questions using the sample policy. If the policy does not cover the question, say so."
}4. Test the draft, then publish when ready
Use Chat preview with the new agent ID, a test user_id and the question “How long do I have to return an unopened item?” Check that the reply says 14 days from delivery. Ask a second question about opened items to check how the agent handles missing information.
When the answers are ready for customers, use Publish an agent. Publishing activates the draft configuration. Use Get an agent to check its status, then follow the quickstart to send a message to the live agent.
Updated about 1 hour ago

