Skip to main content
Knowledge is a structured store of external documents and resources that an agent can consult in order to inform its responses. Instead of relying purely on pre-trained model weights or short-term context, the agent can load, index, and retrieve relevant documents, data, and content. This enables more accurate, up-to-date, and specific answers, especially when dealing with domain-specific or recently changing information.

In the example code

A knowledge instance named us_federal_code is created, to represent a collection of sections of U.S. federal law. Several documents are added viaadd_document(name, url, content_type="text/markdown"), each mapping a shorthand name (“sec-330”, “sec-330a”, etc.) to a URL pointing to Markdown versions of specific legal sections. The agent, “Henry,” is then started with instructions, a model, and thisknowledge store. Because the agent has been given knowledge=us_federal_code, whenever “Henry” is asked a question, it can search through the loaded legal sections to find, quote, or reason over relevant content.
You can find all the code for this example on Github.
images/main/main.py
from autonomy import Agent, Knowledge, Model, Node


async def main(node):
  docs = {
    "sec-330": "https://raw.githubusercontent.com/AlextheYounga/us-federal-code/refs/heads/master/usc/title-15-commerce-and-trade/chapter-9a-weather-modification-activities-or-attempts%3B-reporting-requirement/sec-330.md",
    "sec-330a": "https://raw.githubusercontent.com/AlextheYounga/us-federal-code/refs/heads/master/usc/title-15-commerce-and-trade/chapter-9a-weather-modification-activities-or-attempts%3B-reporting-requirement/sec-330a.md",
    "sec-330b": "https://raw.githubusercontent.com/AlextheYounga/us-federal-code/refs/heads/master/usc/title-15-commerce-and-trade/chapter-9a-weather-modification-activities-or-attempts%3B-reporting-requirement/sec-330b.md",
    "sec-330c": "https://raw.githubusercontent.com/AlextheYounga/us-federal-code/refs/heads/master/usc/title-15-commerce-and-trade/chapter-9a-weather-modification-activities-or-attempts%3B-reporting-requirement/sec-330c.md",
    "sec-330d": "https://raw.githubusercontent.com/AlextheYounga/us-federal-code/refs/heads/master/usc/title-15-commerce-and-trade/chapter-9a-weather-modification-activities-or-attempts%3B-reporting-requirement/sec-330d.md",
    "sec-330e": "https://raw.githubusercontent.com/AlextheYounga/us-federal-code/refs/heads/master/usc/title-15-commerce-and-trade/chapter-9a-weather-modification-activities-or-attempts%3B-reporting-requirement/sec-330e.md",
  }

  us_federal_code = Knowledge("us_federal_code")
  for name, url in docs.items():
    await us_federal_code.add_document(name, url, content_type="text/markdown")

  await Agent.start(
    node=node,
    name="henry",
    instructions="You are Henry, an expert legal assistant",
    model=Model("nova-micro-v1"),
    knowledge=us_federal_code,
  )


Node.start(main)
images/main/Dockerfile
FROM ghcr.io/build-trust/autonomy-python
COPY . .
ENTRYPOINT ["python", "main.py"]
autonomy.yaml
name: example005
pods:
  - name: main-pod
    public: true
    containers:
      - name: main
        image: main
I