Skip to main content

SubAgentDef

Struct SubAgentDef 

Source
pub struct SubAgentDef {
    pub name: String,
    pub description: String,
    pub model: Option<ModelSpec>,
    pub tools: ToolPolicy,
    pub disallowed_tools: Vec<String>,
    pub permissions: SubAgentPermissions,
    pub skills: SkillFilter,
    pub system_prompt: String,
    pub hooks: SubagentHooks,
    pub memory: Option<MemoryScope>,
    pub source: Option<String>,
    pub file_path: Option<PathBuf>,
}

Fields§

§name: String§description: String§model: Option<ModelSpec>§tools: ToolPolicy§disallowed_tools: Vec<String>

Additional denylist applied after the base tools policy.

Populated from tools.except in YAML frontmatter. Deny wins: tools listed here are blocked even when they appear in tools.allow.

§Serde asymmetry (IMP-CRIT-04)

Deserialization reads this field from the nested tools.except key in YAML/TOML frontmatter. Serialization (via #[derive(Serialize)]) writes it as a flat top-level disallowed_tools key — not under tools. Round-trip serialization is therefore not supported: a serialized SubAgentDef cannot be parsed back as a valid frontmatter file. This is intentional for the current MVP but must be addressed before v1.0.0 (see GitHub issue filed under IMP-CRIT-04).

§permissions: SubAgentPermissions§skills: SkillFilter§system_prompt: String§hooks: SubagentHooks

Per-agent hooks (PreToolUse / PostToolUse) from frontmatter.

Hooks are only honored for project-level and CLI-level definitions. User-level definitions (~/.zeph/agents/) have hooks stripped on load.

§memory: Option<MemoryScope>

Persistent memory scope. When set, a memory directory is created at spawn time and MEMORY.md content is injected into the system prompt.

§source: Option<String>

Scope label and filename of the definition file (populated by load / load_all).

Stored as "<scope>/<filename>" (e.g., "project/my-agent.md"). The full absolute path is intentionally not stored to avoid leaking local filesystem layout in diagnostics and /agent list output.

§file_path: Option<PathBuf>

Full filesystem path of the definition file (populated by load_with_boundary).

Used internally by edit/delete operations. Not included in diagnostics output.

Implementations§

Source§

impl SubAgentDef

Source

pub fn parse(content: &str) -> Result<Self, SubAgentError>

Parse a sub-agent definition from its frontmatter+markdown content.

The primary format uses YAML frontmatter delimited by ---:

---
name: my-agent
description: Does something useful
model: claude-sonnet-4-20250514
tools:
  allow:
    - shell
permissions:
  max_turns: 10
skills:
  include:
    - "git-*"
---

You are a helpful agent.

TOML frontmatter (+++) is supported as a deprecated fallback and will emit a tracing::warn! message. It will be removed in v1.0.0.

§Errors

Returns SubAgentError::Parse if the frontmatter delimiters are missing or the content is malformed, and SubAgentError::Invalid if required fields are empty or tools.allow and tools.deny are both specified.

Source

pub fn load(path: &Path) -> Result<Self, SubAgentError>

Load a single definition from a .md file.

When boundary is provided, the file’s canonical path must start with boundary — this rejects symlinks that escape the allowed directory.

§Errors

Returns SubAgentError::Parse if the file cannot be read, exceeds 256 KiB, escapes the boundary via symlink, or fails to parse.

Source

pub fn load_all(paths: &[PathBuf]) -> Result<Vec<Self>, SubAgentError>

Load all definitions from a list of paths (files or directories).

Paths are processed in order; when two entries share the same agent name, the first one wins (higher-priority path takes precedence). Non-existent directories are silently skipped.

For directory entries from user/extra dirs: parse errors are warned and skipped. For CLI file entries (is_cli_source = true): parse errors are hard failures.

§Errors

Returns SubAgentError if a CLI-sourced .md file fails to parse.

Source

pub fn load_all_with_sources( ordered_paths: &[PathBuf], cli_agents: &[PathBuf], config_user_dir: Option<&PathBuf>, extra_dirs: &[PathBuf], ) -> Result<Vec<Self>, SubAgentError>

Load all definitions with scope context for source tracking and security checks.

cli_agents — CLI paths (hard errors on parse failure, no boundary check). config_user_dir — optional user-level dir override. extra_dirs — extra dirs from config.

§Errors

Returns SubAgentError if a CLI-sourced .md file fails to parse.

Source§

impl SubAgentDef

Source

pub fn serialize_to_markdown(&self) -> String

Serialize the definition to YAML frontmatter + markdown body.

Uses WritableRawDef (with correct tools.except nesting) to avoid the IMP-CRIT-04 serde asymmetry. The result can be re-parsed with SubAgentDef::parse.

§Panics

Panics if serde_norway serialization fails (should not happen for valid structs).

Source

pub fn save_atomic(&self, dir: &Path) -> Result<PathBuf, SubAgentError>

Write definition to {dir}/{self.name}.md atomically using temp+rename.

Creates parent directories if needed. Uses tempfile::NamedTempFile in the same directory for automatic cleanup on failure.

§Errors

Returns SubAgentError::Invalid if the agent name fails validation (prevents path traversal). Returns SubAgentError::Io if directory creation, write, or rename fails.

Source

pub fn delete_file(path: &Path) -> Result<(), SubAgentError>

Delete a definition file from disk.

§Errors

Returns SubAgentError::Io if the file does not exist or cannot be removed.

Source

pub fn default_template( name: impl Into<String>, description: impl Into<String>, ) -> Self

Create a minimal definition suitable for the create wizard.

Sets sensible defaults: InheritAll tools, default permissions, empty system prompt.

Trait Implementations§

Source§

impl Clone for SubAgentDef

Source§

fn clone(&self) -> SubAgentDef

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SubAgentDef

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SubAgentDef

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for SubAgentDef

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,