Context of AI x Web3

Last updated on

Context is the information space that the model can see, use, and be influenced in this context. The real challenge is not cramming more content in, but rather clearly distinguishing between system rules, user goals, historical states, tool results, and external documentation.


Why learn this?

LLM does not automatically connect to your database, file system, API, user history, and project documentation. It only generates output based on the current context. If the context is incorrect, missing, or outdated, even the most powerful model will produce unreliable answers.

Many AI applications appear to have problems with "the model not being smart enough," but in reality, they suffer from chaotic context design: treating untrusted web pages as system instructions, old documents as the latest rules, user desires as facts, and leaking the state of the previous task to the next task.

In any scenario involving tool calls, this directly impacts security. If the model cannot see the actual tool results, it can only guess; if the agent does not know its current state, permissions, and budget, it may generate out-of-bounds operations.

First Principles

The model can only act based on the context it sees; the system must decide what can enter the context, with what identity, and how to exit after expiration.

Context is not simply about concatenating long texts; it's a system of information governance. You need to label each type of information with its source, timeliness, permissions, and credibility. Otherwise, the model will mix "what the user said," "what the webpage wrote," "what was found on the blockchain," and "what the system stipulates" in the same layer of processing.

  • Trusted sources should be explicitly labeled : system status, user input, search documents, and tool results should be placed in separate sections.
  • The context must be refreshable : status, configuration, permissions, price, version, and task progress cannot be cached for a long time and then reused.
  • Memories should be revocable : User preferences and historical tasks can enhance the experience, but they should not become hidden permissions or permanent identity assumptions.

Knowledge Nodes

Context Window

The Context Window is the maximum scope of context that a model can handle in a single request. The larger the window, the more information it can hold, but this does not mean that the model will perfectly utilize every detail.

A common problem with long contexts is that you "see the details but don't grasp the main point." If you cram in contract source code, audit reports, governance discussions, and transaction logs, the model may be distracted by irrelevant content or may reference outdated paragraphs.

In real-world products, context windows should be used in conjunction with search, summarization, and structured data. Key status indicators should be provided directly, long documents should be retrieved on demand, and low-confidence content should be isolated and annotated.

Context Engineering

Context engineering is about designing how context enters the model. It includes selecting data sources, sorting, pruning, labeling sources, isolating untrusted content, and determining which information must be queried again each time.

A stable utility agent context is typically more than just "user question + a piece of JSON". It should also include:

  • Current task status
  • Tool returns results
  • Relevant logs or evidence
  • Trusted data sources
  • External inspection results
  • Original User Intent
  • System prohibited items and output schema

The goal of context engineering is not to clutter windows, but to ensure that models work within the correct information hierarchy.

Memory

Memory is information that is retained across requests, such as user preferences, historical tasks, frequently used wallets, project configurations, and the results of the last analysis.

While memory can make agents more efficient, it can also introduce hidden risks. For example, if the system remembers a user's frequently used 0xabc address, it will default to that address for future payments; or if it remembers a user's high risk tolerance, it will relax its confirmation policies for high-risk transactions.

Memory cannot replace real-time authorization. Just because a user previously authorized an action does not mean they still do. All memories involving identity, permissions, assets, or external side effects must be re-bound to the current session and current authorization.

Knowledge Base

The Knowledge Base is a searchable external knowledge base for the system, such as product documentation, SDK documentation, code documentation, forum discussions, FAQs, and internal runbooks.

It's suitable for solving the problem of outdated model knowledge, but it doesn't automatically guarantee correctness. The knowledge base needs to maintain its source, update time, version, applicable networks, and obsolescence status. Otherwise, RAG will simply feed older errors into the model more reliably.

For builders, the knowledge base should at least record:

  • Document source and URL
  • Last updated
  • Applicable Protocol Version
  • Applicable version or operating environment
  • Whether from official or third-party sources
  • Is manual review required?

Location in AI x Web3

Context is the entry point connecting the model and the real-world system. AI is responsible for reasoning, while Web3 is responsible for state and settlement; context determines whether the model sees user fantasies, outdated documents, or verifiable on-chain facts.

A reliable agent typically has a layered context:

  1. Command layer: system rules, tool usage rules, prohibited items.
  2. Task layer: User goal, parameters for this session.
  3. Fact layer: On-chain state, tool results, simulation.
  4. Knowledge layer: documents, standards, forums, historical cases.
  5. Memory layer: User preferences and project configuration.

The clearer the hierarchy, the easier it is to implement access control, prevent prompt injection, and conduct audits.