#ifndef CST_SUBAGENT_H #define CST_SUBAGENT_H /* * Sub-agents: the task(description, prompt, agent?) tool runs one turn of a * child agent with its own context and returns its final report and worker_id. * Pass worker_id on subsequent calls to continue the persisted context. * * Roles: built-in general / explore / plan, plus Markdown files in * /.agent/agents/ and /agents/ (the workspace wins, both win * over built-ins). Frontmatter: name, description, model, tools (allowlist), * profile, max_steps, readonly; the body is the role's instructions. * * Transcripts: /.agent/sessions//sub-.jsonl, with a * sub-.json summary next to each (not listed as sessions). */ #include #include "cst_agent.h" #ifdef __cplusplus extern "C" { #endif #define CST_ROLES_MAX 32 typedef struct { char name[64]; char desc[256]; char source[16]; /* "builtin" | "workspace" | "user" */ char model[128]; /* empty = the parent's */ char profile[64]; char tools[1024]; /* ",a,b," allowlist; empty = all but task */ int max_steps; /* 0 = default */ int read_only; char *prompt; /* role instructions (malloc'd) */ } cst_agent_role_t; /* Roles sorted built-ins first, then by name. Free with cst_roles_free. */ int cst_roles_list(const char *workspace, cst_agent_role_t *out, int max); void cst_roles_free(cst_agent_role_t *v, int n); /* System prompt section listing the roles (malloc'd), or NULL. */ char *cst_subagent_index(const char *workspace); /* Register the task tool (owner "builtin:task") for workspace. */ int cst_subagent_register_tool(const char *workspace); typedef struct { char file[64]; /* "sub-3" */ char role[64]; char desc[160]; char status[32]; /* "done" | "error" | "cancelled" | "running" */ char provider[32], model[128]; int requests, max_steps; long prompt_tokens, cached_tokens, cache_write_tokens, output_tokens; int priced; int cache_known; double cost; char currency[8]; int steps, tools; double ms; long long mtime; } cst_subagent_rec_t; void *cst_worker_budget_new(void); void cst_worker_budget_free(void *budget); void cst_worker_budget_reset(void *budget); char *cst_workers_budget_json(const cst_agent_config_t *cfg); /* Validated JSON configuration, stored in /.agent/workers.json. */ char *cst_workers_config_get(const char *workspace); int cst_workers_config_set(const char *workspace, const char *json, char *err, size_t err_sz); void cst_workers_config_apply(cst_agent_config_t *cfg); int cst_worker_cancel(const char *workspace, const char *parent_id, const char *worker_id); /* This parent session's sub-agent runs, newest first. */ int cst_subagent_list(const char *workspace, const char *parent_id, cst_subagent_rec_t *out, int max); /* Full path of a transcript (sub-.jsonl). */ int cst_subagent_path(const char *workspace, const char *parent_id, const char *file, char *out, size_t out_sz); #ifdef __cplusplus } #endif #endif