Restart conversation support.
The idea here is to let the user restart the conversation, possibly with
a better prompt. This is a common manual workflow, and I'd like to make
it easier.
I hand wrote the agent.go stuff, but Sketch wrote the rest.
Co-Authored-By: sketch <hello@sketch.dev>
diff --git a/ant/ant.go b/ant/ant.go
index 69c17c2..8759883 100644
--- a/ant/ant.go
+++ b/ant/ant.go
@@ -464,6 +464,29 @@
}
}
+func (c *Convo) SubConvoWithHistory() *Convo {
+ id := newConvoID()
+ return &Convo{
+ Ctx: skribe.ContextWithAttr(c.Ctx, slog.String("convo_id", id), slog.String("parent_convo_id", c.ID)),
+ HTTPC: c.HTTPC,
+ URL: c.URL,
+ APIKey: c.APIKey,
+ Model: c.Model,
+ MaxTokens: c.MaxTokens,
+ PromptCaching: c.PromptCaching,
+ Parent: c,
+ // For convenience, sub-convo usage shares tool uses map with parent,
+ // all other fields separate, propagated in AddResponse
+ usage: newUsageWithSharedToolUses(c.usage),
+ mu: c.mu,
+ Listener: c.Listener,
+ ID: id,
+ // Do not copy Budget. Each budget is independent,
+ // and OverBudget checks whether any ancestor is over budget.
+ messages: slices.Clone(c.messages),
+ }
+}
+
// Depth reports how many "sub-conversations" deep this conversation is.
// That it, it walks up parents until it finds a root.
func (c *Convo) Depth() int {
@@ -664,6 +687,11 @@
return toolResults, nil
}
+// GetID returns the conversation ID
+func (c *Convo) GetID() string {
+ return c.ID
+}
+
func (c *Convo) CancelToolUse(toolUseID string, err error) error {
c.muToolUseCancel.Lock()
defer c.muToolUseCancel.Unlock()