Support separate API key for background agent work
Add agent_api_key config option. When set, all LLM calls (experience-mine,
fact-mine, consolidation, knowledge-loop, digest) use this key via
ANTHROPIC_API_KEY env var on the claude subprocess, keeping daemon token
usage on a separate quota from interactive sessions.
Config: {"config": {"agent_api_key": "sk-ant-..."}}
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
aa24c40a1c
commit
2f3ac1ecb6
2 changed files with 18 additions and 6 deletions
|
|
@ -49,6 +49,9 @@ pub struct Config {
|
|||
pub journal_max: usize,
|
||||
/// Ordered context groups for session-start loading.
|
||||
pub context_groups: Vec<ContextGroup>,
|
||||
/// Separate API key for background agent work (daemon jobs).
|
||||
/// If set, passed as ANTHROPIC_API_KEY to model calls.
|
||||
pub agent_api_key: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
|
|
@ -69,6 +72,7 @@ impl Default for Config {
|
|||
source: ContextSource::Store,
|
||||
},
|
||||
],
|
||||
agent_api_key: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -122,6 +126,9 @@ impl Config {
|
|||
if let Some(m) = cfg.get("journal_max").and_then(|v| v.as_u64()) {
|
||||
config.journal_max = m as usize;
|
||||
}
|
||||
if let Some(s) = cfg.get("agent_api_key").and_then(|v| v.as_str()) {
|
||||
config.agent_api_key = Some(s.to_string());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
17
src/llm.rs
17
src/llm.rs
|
|
@ -21,13 +21,18 @@ fn call_model(model: &str, prompt: &str) -> Result<String, String> {
|
|||
fs::write(&tmp, prompt)
|
||||
.map_err(|e| format!("write temp prompt: {}", e))?;
|
||||
|
||||
let result = unsafe {
|
||||
Command::new("claude")
|
||||
.args(["-p", "--model", model, "--tools", "", "--no-session-persistence"])
|
||||
let mut cmd = Command::new("claude");
|
||||
cmd.args(["-p", "--model", model, "--tools", "", "--no-session-persistence"])
|
||||
.stdin(fs::File::open(&tmp).map_err(|e| format!("open temp: {}", e))?)
|
||||
.env_remove("CLAUDECODE")
|
||||
.pre_exec(|| {
|
||||
// Kill this child if the parent dies
|
||||
.env_remove("CLAUDECODE");
|
||||
|
||||
// Use separate API key for agent work if configured
|
||||
if let Some(ref key) = crate::config::get().agent_api_key {
|
||||
cmd.env("ANTHROPIC_API_KEY", key);
|
||||
}
|
||||
|
||||
let result = unsafe {
|
||||
cmd.pre_exec(|| {
|
||||
libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGTERM);
|
||||
Ok(())
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue