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,
|
pub journal_max: usize,
|
||||||
/// Ordered context groups for session-start loading.
|
/// Ordered context groups for session-start loading.
|
||||||
pub context_groups: Vec<ContextGroup>,
|
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 {
|
impl Default for Config {
|
||||||
|
|
@ -69,6 +72,7 @@ impl Default for Config {
|
||||||
source: ContextSource::Store,
|
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()) {
|
if let Some(m) = cfg.get("journal_max").and_then(|v| v.as_u64()) {
|
||||||
config.journal_max = m as usize;
|
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;
|
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)
|
fs::write(&tmp, prompt)
|
||||||
.map_err(|e| format!("write temp prompt: {}", e))?;
|
.map_err(|e| format!("write temp prompt: {}", e))?;
|
||||||
|
|
||||||
let result = unsafe {
|
let mut cmd = Command::new("claude");
|
||||||
Command::new("claude")
|
cmd.args(["-p", "--model", model, "--tools", "", "--no-session-persistence"])
|
||||||
.args(["-p", "--model", model, "--tools", "", "--no-session-persistence"])
|
|
||||||
.stdin(fs::File::open(&tmp).map_err(|e| format!("open temp: {}", e))?)
|
.stdin(fs::File::open(&tmp).map_err(|e| format!("open temp: {}", e))?)
|
||||||
.env_remove("CLAUDECODE")
|
.env_remove("CLAUDECODE");
|
||||||
.pre_exec(|| {
|
|
||||||
// Kill this child if the parent dies
|
// 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);
|
libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGTERM);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue