Lesson 02 — Add a knowledge document (base)

You are here: Lesson 2 of 8 · ← Create an agent · Hub · Next: Integration →

Goal

Create a knowledge base container and enable the agent’s knowledge/memory flags so it can use project knowledge tools.

What you will change

  • Add sg_knowledge_hub.docs
  • Set knowledge = { memory_enabled = true } on sg_agent (memory-only; graph_* attributes were removed in provider ≥ 0.1.42)
  • Full root: steps/02-knowledge/

Why it matters

Agents without a corpus guess. A knowledge base is the shelf where synced docs will live. Lesson 03 fills the shelf from GitHub; this lesson builds the shelf.

ELI5: You buy an empty bookshelf (KB) and tell the agent “you may use the library” (memory/graph flags). Books arrive in the next lesson.

Important distinction

Concept What it is
sg_knowledge_hub Project-scoped container for documents
Agent knowledge = { … } Episodic / graph flags — not a knowledge_base_id binding

There is no per-agent KB id on sg_agent in this pattern. Agents in the project reach synced docs through knowledge tools.

HCL

resource "sg_knowledge_hub" "docs" {
  name        = "aac-docs"
  description = "Agent as Code tutorial knowledge base (documents sync in lesson 03)."
}

resource "sg_agent" "tutor" {
  name        = "aac-tutor"
  description = "Agent as Code tutorial — lesson 02 (knowledge flags)"
  persona     = file("${path.module}/personas/aac-tutor.md")
  # Optional — omit / leave empty to use Aiden's built-in base model
  model_names = length(compact(var.model_names)) > 0 ? compact(var.model_names) : null

  knowledge = {
    memory_enabled = true
  }
}

Apply & verify

cd examples/scenarios/agent-as-code/steps/02-knowledge
# same TF_VAR_* as lesson 01
tofu init && tofu apply
tofu output knowledge_base_name
tofu output knowledge_base_id

Arrange: Aiden knowledge / project settings (or API) where bases are listed.
Sample prompt (chat with aac-tutor):

Search the project knowledge base for anything about Agent as Code. What did you find?

Assert: Agent may say the KB is empty — that is expected until Lesson 03 syncs a source.

Gotchas

  • Creating a KB alone does not ingest files. You need sg_knowledge_source (Lesson 03).
  • Do not confuse memory flags with “this agent only sees KB X.”

Checkpoint

  • aac-docs knowledge base exists
  • Agent has knowledge flags enabled
  • You understand sync comes next

Next: Lesson 03 — Add an integration