ZeroClaw — System Prompt 구성
Layer 2 학습. 실제 소스 코드 기반. 파일:
src/agent/prompt.rs
전체 구조
System prompt는 SystemPromptBuilder가 여러 PromptSection을 순서대로 조립해서 만든다.
SystemPromptBuilder::with_defaults()
→ [IdentitySection, ToolHonestySection, ToolsSection, SafetySection,
SkillsSection, WorkspaceSection, DateTimeSection, RuntimeSection,
ChannelMediaSection]
→ 각 section.build(ctx) 호출
→ 결과를 "\n\n"으로 연결
→ 최종 system prompt 문자열 반환
Agent::turn() 첫 호출 시 딱 한 번 생성되고, history 맨 앞에 push된다.
PromptSection trait
pub trait PromptSection: Send + Sync {
fn name(&self) -> &str;
fn build(&self, ctx: &PromptContext<'_>) -> Result<String>;
}
커스텀 섹션을 만들어서 add_section()으로 추가 가능.
PromptContext — 빌더에게 전달되는 컨텍스트
pub struct PromptContext<'a> {
pub workspace_dir: &'a Path,
pub model_name: &'a str,
pub tools: &'a [Box<dyn Tool>], // 등록된 모든 도구
pub skills: &'a [Skill], // 스킬 목록
pub skills_prompt_mode: SkillsPromptInjectionMode, // Full / Compact
pub identity_config: Option<&'a IdentityConfig>, // AIEOS 등
pub dispatcher_instructions: &'a str, // XML 사용법 (XmlDispatcher일 때)
pub tool_descriptions: Option<&'a ToolDescriptions>, // 로케일 설명
pub security_summary: Option<String>, // 보안 정책 요약
pub autonomy_level: AutonomyLevel, // ReadOnly / Supervised / Full
}
섹션별 상세
1. IdentitySection
workspace의 identity 파일들을 읽어 주입.
읽는 파일 목록 (있는 것만):
AGENTS.md, SOUL.md, TOOLS.md, IDENTITY.md,
USER.md, HEARTBEAT.md, BOOTSTRAP.md, MEMORY.md
AIEOS 설정이 있으면 JSON/Markdown 형식 persona 먼저 렌더링.
파일 하나당 최대 20,000자 — 초과 시 truncate.
네 용도: workspace/.zeroclaw/AGENTS.md에 일정 프로그램의 역할과 동작 규칙을 써두면 매 대화 시작마다 LLM이 읽어.
2. ToolHonestySection
짧고 고정된 지침. 도구 결과 위조 금지.
- NEVER fabricate tool results.
- If a tool call fails, report the error.
- When unsure, ask rather than guessing.
3. ToolsSection
등록된 모든 도구를 LLM에게 노출. 가장 중요한 섹션.
## Tools
- **shell**: 쉘 명령을 실행한다.
Parameters: `{"type":"object","properties":{"command":{"type":"string"}}}`
- **fetch_assignments**: 대학 LMS에서 미제출 과제 조회.
Parameters: `{"type":"object","properties":{"course":{...}}}`
(XmlToolDispatcher일 때 여기에 <tool_call> 사용법 추가)
tool_descriptions가 있으면 로케일 파일에서 설명을 가져온다 (다국어 지원).
4. SafetySection
Autonomy 레벨에 따라 내용이 달라진다.
공통 (항상 포함):
- Do not exfiltrate private data.
- Prefer `trash` over `rm`.
Supervised (기본):
- Do not run destructive commands without asking.
- When in doubt, ask before acting externally.
Full:
- Execute allowed actions directly (ask 지침 없음)
- If a tool is blocked, explain the restriction.
ReadOnly:
- This runtime is read-only for side effects.
security_summary가 있으면 ### Active Security Policy 섹션으로 추가:
**Autonomy level**: Supervised
**Allowed shell commands**: `git`, `cargo`, `ls`
**Forbidden paths**: `/etc`, `/sys`
→ LLM이 허용/금지 명령어를 미리 알고 trial-and-error 없이 계획 가능.
5. SkillsSection
Skills 목록을 XML 형식으로 주입.
Full 모드: 스킬 전체 내용 (지침 + 도구) 포함.
<available_skills>
<skill>
<n>deploy</n>
<description>Release safely</description>
<instruction>Run smoke tests before deploy.</instruction>
<tools>
<tool><n>release_checklist</n><kind>shell</kind></tool>
</tools>
</skill>
</available_skills>
Compact 모드: 위치만 알려주고 필요할 때 read_skill(name) 도구로 로드.
<skill>
<n>deploy</n>
<location>skills/deploy/SKILL.md</location>
Use read_skill(name) to load details.
</skill>
→ token 절약, 대신 LLM이 필요 시 추가 tool call 발생.
6. WorkspaceSection
## Workspace
Working directory: `/home/user/.zeroclaw/workspace`
7. DateTimeSection
## Current Date & Time
2026-03-22 15:30:00 (KST)
매 대화 시작마다 현재 시각 주입. 일정 관리 프로그램에 매우 중요.
8. RuntimeSection
## Runtime
Host: myserver | OS: linux | Model: qwen3-7b
9. ChannelMediaSection
Telegram 등 채널에서 전달된 미디어 마커 설명.
- `[Voice] <text>` — 음성 메시지 (이미 텍스트로 변환됨)
- `[IMAGE:<path>]` — 이미지 첨부파일
- `[Document: <n>] <path>` — 파일 첨부
최종 System Prompt 형태
## Project Context
### AGENTS.md
[내용]
### SOUL.md
[내용]
## CRITICAL: Tool Honesty
...
## Tools
- **shell**: ...
- **fetch_assignments**: ...
## Tool Use Protocol ← XmlDispatcher일 때만
<tool_call>{"name": ...}</tool_call>
## Safety
...
### Active Security Policy ← security_summary 있을 때
...
## Current Date & Time
2026-03-22 15:30:00 (KST)
## Runtime
Host: ... | OS: ... | Model: ...
## Workspace
Working directory: ...
## Channel Media Markers
...
커스터마이징
struct ScheduleContextSection;
impl PromptSection for ScheduleContextSection {
fn name(&self) -> &str { "schedule_context" }
fn build(&self, ctx: &PromptContext<'_>) -> Result<String> {
// 오늘 마감인 과제 목록을 매 대화마다 주입
let today = chrono::Local::now().format("%Y-%m-%d");
Ok(format!("## Today's Schedule\n\nDate: {today}\n[오늘 일정 로드]"))
}
}
// 빌더에 추가
SystemPromptBuilder::with_defaults()
.add_section(Box::new(ScheduleContextSection))
AGENTS.md — 가장 실용적인 커스터마이징
코드 수정 없이 agent 동작을 바꾸는 가장 쉬운 방법.
<!-- workspace/.zeroclaw/AGENTS.md -->
# 일정 관리 에이전트
너는 사용자의 개인 일정 관리 에이전트다.
## 역할
- 대학 LMS에서 과제를 자동으로 감지하고 일정에 등록한다.
- PDF 변환 작업을 위임하고 결과를 보고한다.
- 매일 오전 9시 오늘의 일정을 텔레그램으로 알린다.
## 규칙
- 파일을 삭제하기 전 반드시 확인을 구한다.
- 학교 크롤링은 항상 fetch_assignments 도구를 사용한다.
관련
- agent-loop — turn() 첫 호출 시 build_system_prompt() 호출
- tool-system — ToolsSection이 tools 목록 활용
- tool-dispatcher — XmlDispatcher는 prompt_instructions() 추가
- config-schema — autonomy_level, security_summary 출처
- overview — ZeroClaw 학습 지도