on main help sign in
fix: quota for subagents in copilot
commita94866c85c68f036c343710145bbc5e71e755382 authorKujtim Hoxha <kujtimii.h@gmail.com> dateMon 5 Jan 2026, 12:31 (9 months ago) parentaa4f380
3 files changed+15−14
internal/agent/agentic_fetch_tool.go+1−1 internal/agent/coordinator.go+9−9 internal/oauth/copilot/client.go+5−4
internal/agent/agentic_fetch_tool.go+1−1
@@ -143,7 +143,7 @@ func (c *coordinator) agenticFetchTool(_ context.Context, client *http.Client) (
143143 return fantasy.ToolResponse{}, fmt.Errorf("error creating prompt: %s", err)
144144 }
145145
146− _, small, err := c.buildAgentModels(ctx)
146+ _, small, err := c.buildAgentModels(ctx, true)
147147 if err != nil {
148148 return fantasy.ToolResponse{}, fmt.Errorf("error building models: %s", err)
149149 }
internal/agent/coordinator.go+9−9
@@ -317,7 +317,7 @@ func mergeCallOptions(model Model, cfg config.ProviderConfig) (fantasy.ProviderO
317317}
318318
319319func (c *coordinator) buildAgent(ctx context.Context, prompt *prompt.Prompt, agent config.Agent, isSubAgent bool) (SessionAgent, error) {
320− large, small, err := c.buildAgentModels(ctx)
320+ large, small, err := c.buildAgentModels(ctx, isSubAgent)
321321 if err != nil {
322322 return nil, err
323323 }
@@ -441,7 +441,7 @@ func (c *coordinator) buildTools(ctx context.Context, agent config.Agent) ([]fan
441441}
442442
443443// TODO: when we support multiple agents we need to change this so that we pass in the agent specific model config
444−func (c *coordinator) buildAgentModels(ctx context.Context) (Model, Model, error) {
444+func (c *coordinator) buildAgentModels(ctx context.Context, isSubAgent bool) (Model, Model, error) {
445445 largeModelCfg, ok := c.cfg.Models[config.SelectedModelTypeLarge]
446446 if !ok {
447447 return Model{}, Model{}, errors.New("large model not selected")
@@ -456,7 +456,7 @@ func (c *coordinator) buildAgentModels(ctx context.Context) (Model, Model, error
456456 return Model{}, Model{}, errors.New("large model provider not configured")
457457 }
458458
459− largeProvider, err := c.buildProvider(largeProviderCfg, largeModelCfg)
459+ largeProvider, err := c.buildProvider(largeProviderCfg, largeModelCfg, isSubAgent)
460460 if err != nil {
461461 return Model{}, Model{}, err
462462 }
@@ -466,7 +466,7 @@ func (c *coordinator) buildAgentModels(ctx context.Context) (Model, Model, error
466466 return Model{}, Model{}, errors.New("large model provider not configured")
467467 }
468468
469− smallProvider, err := c.buildProvider(smallProviderCfg, largeModelCfg)
469+ smallProvider, err := c.buildProvider(smallProviderCfg, largeModelCfg, isSubAgent)
470470 if err != nil {
471471 return Model{}, Model{}, err
472472 }
@@ -583,7 +583,7 @@ func (c *coordinator) buildOpenrouterProvider(_, apiKey string, headers map[stri
583583 return openrouter.New(opts...)
584584}
585585
586−func (c *coordinator) buildOpenaiCompatProvider(baseURL, apiKey string, headers map[string]string, extraBody map[string]any, providerID string) (fantasy.Provider, error) {
586+func (c *coordinator) buildOpenaiCompatProvider(baseURL, apiKey string, headers map[string]string, extraBody map[string]any, providerID string, isSubAgent bool) (fantasy.Provider, error) {
587587 opts := []openaicompat.Option{
588588 openaicompat.WithBaseURL(baseURL),
589589 openaicompat.WithAPIKey(apiKey),
@@ -592,7 +592,7 @@ func (c *coordinator) buildOpenaiCompatProvider(baseURL, apiKey string, headers
592592 // Set HTTP client based on provider and debug mode.
593593 var httpClient *http.Client
594594 if providerID == string(catwalk.InferenceProviderCopilot) {
595− httpClient = copilot.NewClient(c.cfg.Options.Debug)
595+ httpClient = copilot.NewClient(isSubAgent, c.cfg.Options.Debug)
596596 } else if c.cfg.Options.Debug {
597597 httpClient = log.NewHTTPClient()
598598 }
@@ -714,7 +714,7 @@ func (c *coordinator) isAnthropicThinking(model config.SelectedModel) bool {
714714 return false
715715}
716716
717−func (c *coordinator) buildProvider(providerCfg config.ProviderConfig, model config.SelectedModel) (fantasy.Provider, error) {
717+func (c *coordinator) buildProvider(providerCfg config.ProviderConfig, model config.SelectedModel, isSubAgent bool) (fantasy.Provider, error) {
718718 headers := maps.Clone(providerCfg.ExtraHeaders)
719719 if headers == nil {
720720 headers = make(map[string]string)
@@ -754,7 +754,7 @@ func (c *coordinator) buildProvider(providerCfg config.ProviderConfig, model con
754754 }
755755 providerCfg.ExtraBody["tool_stream"] = true
756756 }
757− return c.buildOpenaiCompatProvider(baseURL, apiKey, headers, providerCfg.ExtraBody, providerCfg.ID)
757+ return c.buildOpenaiCompatProvider(baseURL, apiKey, headers, providerCfg.ExtraBody, providerCfg.ID, isSubAgent)
758758 case hyper.Name:
759759 return c.buildHyperProvider(baseURL, apiKey)
760760 default:
@@ -799,7 +799,7 @@ func (c *coordinator) Model() Model {
799799
800800func (c *coordinator) UpdateModels(ctx context.Context) error {
801801 // build the models again so we make sure we get the latest config
802− large, small, err := c.buildAgentModels(ctx)
802+ large, small, err := c.buildAgentModels(ctx, false)
803803 if err != nil {
804804 return err
805805 }
internal/oauth/copilot/client.go+5−4
@@ -14,14 +14,15 @@ import (
1414
1515// NewClient creates a new HTTP client with a custom transport that adds the
1616// X-Initiator header based on message history in the request body.
17−func NewClient(debug bool) *http.Client {
17+func NewClient(isSubAgent, debug bool) *http.Client {
1818 return &http.Client{
19− Transport: &initiatorTransport{debug: debug},
19+ Transport: &initiatorTransport{debug: debug, isSubAgent: isSubAgent},
2020 }
2121}
2222
2323type initiatorTransport struct {
24− debug bool
24+ debug bool
25+ isSubAgent bool
2526}
2627
2728func (t *initiatorTransport) RoundTrip(req *http.Request) (*http.Response, error) {
@@ -58,7 +59,7 @@ func (t *initiatorTransport) RoundTrip(req *http.Request) (*http.Response, error
5859 // variations in the JSON while avoiding full unmarshalling overhead.
5960 initiator := userInitiator
6061 assistantRolePattern := regexp.MustCompile(`"role"\s*:\s*"assistant"`)
61− if assistantRolePattern.Match(bodyBytes) {
62+ if assistantRolePattern.Match(bodyBytes) || t.isSubAgent {
6263 slog.Debug("Setting X-Initiator header to agent (found assistant messages in history)")
6364 initiator = agentInitiator
6465 } else {