|
1 | | -# Structured Context Language |
| 1 | +# Structured Context Language (SCL) |
2 | 2 |
|
3 | | -## Overview |
4 | | -People are familiar with SQL (Structured Query Language), which is used to interact with databases. Today, as we face Large Language Models (LLMs), the focus is shifting from prompt engineering to context engineering. |
| 3 | +## Vision |
5 | 4 |
|
6 | | -In this repository, we aim to build a Structured Context Language (SCL) to occupy a niche analogous to SQL, drawing inspiration from context engineering practices. |
| 5 | +Everyone is familiar with SQL for interacting with databases. In the era of large language models, our focus is shifting from prompt engineering to context engineering. |
7 | 6 |
|
8 | | -We hope that through this effort, we can distill a middleware solution. This middleware would provide a standard interface for AI agents, much like Hibernate serves as a standard ORM interface for Java applications. |
| 7 | +In this project, we aim to build a Structured Context Language (SCL), drawing on the practices of context engineering to occupy a niche similar to that of SQL. |
| 8 | + |
| 9 | +Through this practice, we hope to distill a middleware layer. This middleware will provide a standardized interface for agents, playing a role analogous to Hibernate for Java applications. |
9 | 10 |
|
10 | 11 | ## Deconstructing SCL |
11 | 12 |
|
12 | | -If we consider prompts as a query language for Large Language Models (LLM), then context engineering is undoubtedly an implementation of this query language. We can deconstruct context engineering along three independent dimensions: |
13 | | - |
14 | | -- Business Content: Specific instructions for particular prompts and scenarios. |
15 | | -- Tool Invocation: Various tools the LLM can use to obtain additional external data. |
16 | | -- Memory Management: In multi-turn conversation scenarios, determining which historical content is relevant to the current query. |
17 | | - |
18 | | -> We can view tool invocation as a spatial expansion of information and memory management as an expansion of information along the temporal dimension. |
19 | | -
|
20 | | -Considering that in engineering practice, we can implement interactions for memory management through tool invocation, the extended querying of information within context engineering can therefore be accomplished using a standardized interface and further summarized into a standardized workflow. |
21 | | - |
22 | | -Inspired by the progressive loading mechanism of Claude Skill, we have also observed that autonomous selection of tools by the LLM can be achieved through progressive loading across different tools. Unlike stored procedures in SQL, which are defined and explicitly called for execution, progressive loading provides an additional layer of autonomy. |
23 | | - |
24 | | -## Use case |
25 | | -> The Autonomy Slider —— Reference Karpathy's speech on Software 3.0. Show me the diff in vivid. |
26 | | -
|
27 | | -``` |
28 | | -Configurable + Autonomy by LLM via feedback control |
29 | | -Autonomy by LLM via feedback control(metric or history) |
30 | | -Autonomy by LLM |
31 | | -Configurable |
32 | | -HardCode |
33 | | -``` |
34 | | - |
35 | | -- [ ] Should we make a middleware just input as prompt and output as result?(Autonomy) |
36 | | -- [ ] We provides workflow and let people able to config it.(Configurable) |
37 | | -- [ ] We provides sdk let people implements their own.(Hardcode) |
38 | | - |
39 | | -- [x] Obversbility —— otel. |
40 | | -> |
41 | | -``` |
42 | | -docker run -p 8000:8000 -p 4317:4317 -p 4318:4318 ghcr.io/ctrlspice/otel-desktop-viewer:latest-amd64 |
43 | | -export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317" |
44 | | -export OTEL_TRACES_EXPORTER="otlp" |
45 | | -export OTEL_EXPORTER_OTLP_PROTOCOL="grpc" |
46 | | -``` |
47 | | - |
48 | | -- [ ] Function selction. |
49 | | - - [x] "Progressive loading" base on RAG. (Autonomy) |
50 | | - - [ ] Hard code memory tool invoke. (Autonomy or defualt? tbd) |
51 | | - - [x] Hardcode control by human, as index hint for SQL. |
52 | | - |
53 | | -- [ ] File format Autonomy, took PDF format as example. |
54 | | - - [ ] Context auto into markdown.(Autonomy) |
55 | | - - [ ] Context auto embedding for RAG.(Autonomy) |
56 | | - - [ ] Or Hardcode control by human outside our process. |
57 | | - |
58 | | -- [ ] Content Autonomy. |
59 | | - - [ ] RAG support by default.(Autonomy) |
60 | | - - [ ] Hard code as input prompt content.(Hardcode control by human) |
61 | | -``` |
62 | | -for EMBEDDING service, using siliconflow fow now as poc |
63 | | -export EMBEDDING_API_KEY=<your_siliconflow_api_key> |
64 | | -``` |
65 | | - |
66 | | -``` |
67 | | -docker run -d --name pgvector -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=postgres -e POSTGRES_DB=postgres -p 5432:5432 ankane/pgvector:v0.5.1 |
68 | | -`` |
69 | | -
|
70 | | -## todo |
71 | | -Article/Blog |
72 | | -Investigating how to reuse powermom? |
73 | | -Find some agent bench mark for testing.——Mind2Web or WebArena? |
| 13 | +If we treat a prompt as a query language for large language models (LLMs), then context engineering is certainly one implementation of that query language. We can deconstruct context engineering along three independent dimensions: |
| 14 | + |
| 15 | +- **Business content**: Concrete instructions tailored to specific prompts and scenarios. |
| 16 | +- **Tool calling**: Various tools available to the LLM to fetch additional external data. |
| 17 | +- **Memory management**: In multi-turn conversations, deciding which historical content is relevant to the current query. |
| 18 | + |
| 19 | +> We can view tool calling as a spatial expansion of information, and memory management as a temporal expansion of information. |
| 20 | +
|
| 21 | +In engineering practice, we can manage memory through tool calls. Therefore, within context engineering, the expansion of information can be accomplished via a standardized interface, which can be further distilled into a standardized workflow. |
| 22 | + |
| 23 | +Inspired by the progressive loading mechanism of Claude Skills, we also see that between different tools, progressive loading can allow the model to autonomously select tools. Unlike stored procedures that are explicitly defined and called in SQL, this provides extra autonomy through progressive loading. |
| 24 | + |
| 25 | +## SCL Agent Loop: A Unified Agent Runtime |
| 26 | + |
| 27 | +Building on the above ideas, SCL provides a standardized agent loop as the runtime middleware for context engineering. It unifies the processing of these three dimensions into an event-driven execution model. |
| 28 | + |
| 29 | +### Design Principles |
| 30 | + |
| 31 | +- **Minimalist YOLO Mode** |
| 32 | + No built-in TODO lists, planning, sub-agents, or background bash processes. Developers externalize state through files, compose tools through bash, and implement skill execution by spawning new tasks. We want the framework to do one thing——run an agent——and give the user full control and observability. |
| 33 | + |
| 34 | +- **Unified Provider Interface** |
| 35 | + A single API supporting Anthropic, OpenAI, Google, xAI, Groq, Cerebras, OpenRouter, and any OpenAI-compatible endpoint. Provides streaming, tool calls with TypeBox schema validation, reasoning/thinking support, seamless cross-provider context handoff, and token and cost tracking. |
| 36 | + |
| 37 | +- **Tool Registration and Selection** |
| 38 | + Built-in tool registry that maintains tool metadata and descriptions. The agent uses a RAG-based mechanism to progressively load available tools, injecting only the relevant tool definitions into the context when needed. This avoids context bloat from full tool descriptions and preserves model autonomy while respecting progressive loading. |
| 39 | + |
| 40 | +- **Pluggable Content Compression** |
| 41 | + A hot-swappable interface for content compression strategies. During long conversations, a customizable compressor can distill historical messages to reduce token consumption while retaining critical information, improving stability for long-running agents. |
| 42 | + |
| 43 | +- **Prompt Templates** |
| 44 | + Structured template support for business content, facilitating reuse, version management, and team collaboration. Templates can incorporate proven prompt patterns from context engineering practice. |
| 45 | + |
| 46 | +- **Multiple Runtime Forms** |
| 47 | + - **RESTful (containerized)** — Deployed as a service, providing API access. |
| 48 | + - **Local TUI** — Interactive terminal usage with slash commands and session management. |
| 49 | + - **Library** — Directly imported for secondary development and deep integration. |
| 50 | + |
| 51 | +- **Observability** |
| 52 | + Transparent event streaming across the entire workflow: tool call parameters and results, every incremental model output, and internal state changes are all traceable. This is essential for debugging, evaluation, and building trust. |
| 53 | + |
| 54 | +- **Built-in Toolset** |
| 55 | + Out-of-the-box tools covering common coding and operations tasks: |
| 56 | + - File read/write |
| 57 | + - Search (grep, find) |
| 58 | + - Bash |
| 59 | + - Git |
| 60 | + - Create cron jobs |
| 61 | + - Other tools available for function call branching |
| 62 | + |
| 63 | + Tools can be extended through the registration mechanism, supporting both native implementations and CLI-wrapped commands. |
| 64 | + |
| 65 | +### How It Reflects SCL’s Philosophy |
| 66 | + |
| 67 | +- **Unified Information Expansion** |
| 68 | + Both tool calling (spatial expansion) and memory management (temporal expansion) are handled within the agent loop through the same standardized tool interface. Memory management is no longer a special internal mechanism; it is invoked, recorded, and observed like any other tool. |
| 69 | + |
| 70 | +- **Progressive Loading Engineered** |
| 71 | + The RAG-based tool selection extends the progressive loading concept from “skill files” to all tools. The model first understands the need, then fetches tool descriptions on demand, and autonomously decides which resources to use. This balances context efficiency with autonomy. |
| 72 | + |
| 73 | +- **Middleware Positioning** |
| 74 | + Just as Hibernate provides a standard abstraction for persistence in Java applications, the SCL Agent Loop aims to provide a standardized interface for context management in agent applications. It encapsulates provider differences, tool execution, compression strategies, and runtime modes, allowing developers to focus on business prompts and task-flow design. |
0 commit comments