Repository navigation
feat(assistant): show each message's tokens and choose the effort on a ChatGPT plan #3575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b3bee04
3a685f7
d1682a9
88a8b61
7342d27
10da12c
88c5510
306a9ff
0fd1e7d
6d6c16d
cc0ff11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -676,6 +676,17 @@ fn ask(s: &mut Session, args: &[String], saved: Option<&Saved>, env: &Environmen | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| let pictures = ask_pictures(args)?; | ||||||||||||||||||||||||
| eprintln!("[{} · {}]", cfg.provider, cfg.model); | ||||||||||||||||||||||||
| // A level asked for that the model doesn't take isn't sent: said. | ||||||||||||||||||||||||
| if cfg.login() && cfg.reasoning != Some(false) && !cfg.effort.trim().is_empty() && cfg.effort.trim() != cfg.effort_sent() { | ||||||||||||||||||||||||
| let mark = s.notice_mark(); | ||||||||||||||||||||||||
| s.notify( | ||||||||||||||||||||||||
| format!("the effort {:?} isn't among those listed for {}; {} is used", cfg.effort.trim(), cfg.model, cfg.effort_sent()), | ||||||||||||||||||||||||
| false, | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| for n in s.notices_since(mark) { | ||||||||||||||||||||||||
| eprintln!("rustgis-cli: {}", n.text); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+680
to
+689
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The effort notice is written with Suggested change:
Suggested change
Category: agents-md
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 0fd1e7d: the effort note is a |
||||||||||||||||||||||||
| let yes = args.iter().any(|a| a == "--yes"); | ||||||||||||||||||||||||
| let trace_key = cfg.key.clone(); | ||||||||||||||||||||||||
| let mut a = Agent::new(cfg, s); | ||||||||||||||||||||||||
|
|
@@ -719,6 +730,10 @@ fn ask(s: &mut Session, args: &[String], saved: Option<&Saved>, env: &Environmen | |||||||||||||||||||||||
| allow | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| show(&a); | ||||||||||||||||||||||||
| if let Some(u) = a.usage() { | ||||||||||||||||||||||||
| let least = if u.partial { "at least " } else { "" }; | ||||||||||||||||||||||||
| eprintln!("(tokens: {least}{} in, {} out)", u.input, u.output); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| if a.transcript.iter().any(|e| matches!(e, Entry::Error(_))) { | ||||||||||||||||||||||||
| return Err("the assistant couldn't finish".into()); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,6 +166,9 @@ pub struct Agent { | |
| allowed: Vec<String>, | ||
| /// The agents on this computer the model may delegate to ([`acp`]). | ||
| harnesses: Vec<&'static acp::AgentSpec>, | ||
| /// The tokens this message's requests took, subagents' included; agent threads on this | ||
| /// computer bill their own ([`Agent::usage`]). | ||
| usage: provider::Usage, | ||
| /// Model requests left for this message (a subagent shares its parent's budget). | ||
| max_steps: u32, | ||
| /// Agent threads on this computer, working or waiting for a follow-up. | ||
|
|
@@ -248,6 +251,7 @@ impl Agent { | |
| threads_started: 0, | ||
| delegations: Vec::new(), | ||
| reports: Vec::new(), | ||
| usage: provider::Usage::default(), | ||
| max_steps: MAX_STEPS, | ||
| } | ||
| } | ||
|
|
@@ -333,7 +337,11 @@ impl Agent { | |
| } | ||
| waiting.push_str(&message) | ||
| } | ||
| _ => a.turns.push(Turn::User(message, Vec::new())), | ||
| _ => { | ||
| a.turns.push(Turn::User(message, Vec::new())); | ||
| // A turn of its own counts afresh; joining a message still waiting adds to it. | ||
| a.usage = provider::Usage::default(); | ||
| } | ||
| } | ||
| a.steps = 0; | ||
| a.retries = 0; | ||
|
|
@@ -465,6 +473,16 @@ impl Agent { | |
| Scope::assistant(self.conversation, self.live.clone()) | ||
| } | ||
|
|
||
| /// The tokens the last message's requests took so far, as the provider counts them. `None` when | ||
| /// it doesn't say. | ||
| pub fn usage(&self) -> Option<provider::Usage> { | ||
| let mut usage = self.usage; | ||
| if let Some(child) = &self.child { | ||
| usage.add(child.usage); | ||
| } | ||
| (usage.input > 0 || usage.output > 0).then_some(usage) | ||
| } | ||
|
|
||
| /// Changes in the generation tell a caller its response is stale. | ||
| pub fn generation(&self) -> u64 { | ||
| self.generation | ||
|
|
@@ -477,6 +495,7 @@ impl Agent { | |
| self.turns.clear(); | ||
| self.transcript.clear(); | ||
| self.state = State::Idle; | ||
| self.usage = provider::Usage::default(); | ||
| self.steps = 0; | ||
| self.last_context.clear(); | ||
| self.always.clear(); | ||
|
|
@@ -575,7 +594,11 @@ impl Agent { | |
| ))); | ||
| } | ||
| } | ||
| _ => self.turns.push(Turn::User(message, pictures)), | ||
| _ => { | ||
| self.turns.push(Turn::User(message, pictures)); | ||
| // A turn of its own counts afresh; joining one still waiting adds to its count. | ||
| self.usage = provider::Usage::default(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compaction carries the previous answer's tokens into the next message. Manual compaction covers every turn. It leaves a single summary-only user turn, and the next message joins that turn without resetting the per-message count. As a result, the count for the next message includes the completed answer's tokens. The displayed "Tokens for this message" value is then too high. The conversation content is not affected. Reset the count so that tokens from requests before compaction do not carry into the next message. Choose the reset point in the compaction flow. The choice decides whether the summary request's own tokens count toward the next message. Either choice must exclude the earlier answer.
|
||
| } | ||
| } | ||
| self.steps = 0; | ||
| self.retries = 0; | ||
|
|
@@ -812,6 +835,10 @@ impl Agent { | |
| } | ||
| self.preview = None; | ||
| let parsed = resp.as_ref().map_err(Clone::clone).and_then(|r| provider::parse_reply(self.config.api(), r)); | ||
| // A request that failed may still have been charged for, without saying how much. | ||
| if parsed.is_err() { | ||
| self.usage.partial = true; | ||
| } | ||
| if self.config.provider == "openrouter" | ||
| && matches!(&parsed, Err(e) if e.status == Some(404) && { | ||
| let detail = e.detail.to_ascii_lowercase(); | ||
|
|
@@ -848,6 +875,8 @@ impl Agent { | |
| } | ||
| self.retries = 0; | ||
| if let Ok(reply) = &parsed { | ||
| // A request that doesn't say is noted, so the total isn't taken for the whole. | ||
| self.usage.add(reply.usage.unwrap_or(provider::Usage { partial: true, ..Default::default() })); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The partial flag covers requests that reply without counts, but not requests that fail. Only Suggested direction: when the reply is an error on a 2xx response (a stream that was cut, so tokens may have been used), set Confidence: medium. It depends on whether the providers in use bill cut streams. Category: bug
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 7342d27, as above.
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| self.transcript.extend(reply.notes.iter().cloned().map(Entry::Note)); | ||
| } | ||
| if let State::Compacting { upto, resume } = self.state { | ||
|
|
@@ -1129,6 +1158,7 @@ impl Agent { | |
| let Some(child) = self.child.take() else { return Step::Done }; | ||
| // Its steps count against this message's budget; its "always" approvals stay. | ||
| self.steps = self.steps.saturating_add(child.steps); | ||
| self.usage.add(child.usage); | ||
| for key in &child.always { | ||
| if self.always.contains(key) { | ||
| continue; | ||
|
|
@@ -1241,10 +1271,16 @@ impl Agent { | |
| if !self.busy() { | ||
| return; | ||
| } | ||
| // A request stopped on its way may have been charged for without saying. | ||
| if matches!(self.state, State::Waiting | State::Compacting { .. }) { | ||
| self.usage.partial = true; | ||
| } | ||
| if let Some(child) = self.child.as_mut() { | ||
| child.stop(); | ||
| self.show_child(); | ||
| self.child = None; | ||
| if let Some(child) = self.child.take() { | ||
| self.usage.add(child.usage); | ||
| } | ||
| } | ||
| self.halt(Entry::Note(Note::new("Stopped.")), "Stopped by the user.", "Stopped by the user."); | ||
| } | ||
|
|
@@ -1294,7 +1330,9 @@ impl Agent { | |
| fn halt(&mut self, why: Entry, queued: &str, interrupted: &str) { | ||
| self.live.0.store(false, Ordering::SeqCst); | ||
| self.pending_policy = None; | ||
| self.child = None; | ||
| if let Some(child) = self.child.take() { | ||
| self.usage.add(child.usage); | ||
| } | ||
| self.retrying_summary = None; | ||
| self.retries = 0; | ||
| self.preview = None; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The effort notice now goes through
s.notify, which answers the earliereprintln!concern. The test gap from that thread is still open, and the code it points at has changed, so this is the new part of the concern. AGENTS.md's "Test both ways" rule asks for a lossy case (a saved effort such ashighthat the model's list lacks, which must give the notice) and a clean case (a listed effort, or none set, which must give none). Nothing in the diff exercises either.The check is inline in
ask, after a network catalog fetch, so it is hard to test there. Moving the condition intoConfig(for exampleConfig::effort_dropped() -> bool, next toeffort_sent) would letcrates/assistanttests cover both cases, and the CLI would only format the notice.Category: agents-md