[feature] Rewrite chat_with_model into proper subagent tool with configurable model roles #924

Closed
opened 2026-06-04 11:32:57 +02:00 by sleepy · 0 comments
Owner

Feature Request

The current chat_with_model tool (src/ai_interaction.py:174-210) is a raw LLM relay — it sends a single message to a model and returns the response. It has no concept of:

  • Model roles (default, teacher, coding)
  • Multi-turn subagent conversations
  • Context injection from the parent conversation
  • System prompt configuration

Meanwhile, ask_teacher is a separate hardcoded escalation path in src/teacher_escalation.py that duplicates much of this logic.

What I Want

A unified subagent tool that replaces both chat_with_model and the ad-hoc teacher escalation with a configurable, role-aware subagent system:

Default Behavior

User: "Write a Python function to sort a list"
Agent: [calls subagent tool with default model, inherits conversation context]
→ Response from subagent using same model as parent

Role-Based Routing

User: "Ask the coder to implement this"
Agent: [calls subagent tool with role=coding]
→ Uses the coding_model from settings (see #922)

User: "Ask the teacher for help"
Agent: [calls subagent tool with role=teacher]  
→ Uses the teacher_model from settings

Explicit Model Override

User: "What would GPT-4 say about this?"
Agent: [calls subagent with model=gpt-4]
→ Resolves model name to endpoint

Proposed Design

Settings (depends on #922)

  • default_model — same as current
  • coding_model / coding_endpoint_id — for coding role
  • teacher_model — for teacher role (already exists)
  • Subagent inherits parent model by default

Tool Schema

{
  "name": "subagent",
  "parameters": {
    "task": "Description of what to accomplish",
    "role": "default | coding | teacher | <model_name>",
    "context": "Optional extra context to inject",
    "system_prompt": "Optional system prompt override",
    "max_turns": 1
  }
}

Implementation Notes

  • role=default → uses the same model/endpoint as the parent conversation
  • role=coding → resolves to coding_model + coding_endpoint_id
  • role=teacher → resolves to teacher_model (replaces ask_teacher escalation)
  • role=<model_name> → resolves via _endpoint_model_from_cache (current chat_with_model behavior)
  • Single-turn by default (max_turns=1), but supports multi-turn if needed
  • Inherits parent conversation context (last N messages) for continuity

Migration

  • Keep chat_with_model as a thin alias that calls subagent(role=<resolved_model>) for backward compatibility
  • Keep ask_teacher as an alias for subagent(role=teacher)
  • Tool name map already has aliases: ask_model → chat_with_model, chat_model → chat_with_model

Files to Change

  • src/ai_interaction.py — rewrite do_chat_with_model into do_subagent
  • src/teacher_escalation.py — route ask_teacher through subagent
  • src/tool_metadata.py — update descriptions
  • src/tool_name_map.py — add subagent → subagent, delegate → subagent
  • src/settings.py — add coding model keys
  • routes/ — any settings UI changes for model role config
  • #921 — Settings persistence (must be fixed first)
  • #922 — Coding model setting (prerequisite)
  • #590 — Autoresearch as agent tool (related but separate feature)
## Feature Request The current `chat_with_model` tool (`src/ai_interaction.py:174-210`) is a raw LLM relay — it sends a single message to a model and returns the response. It has no concept of: - Model roles (default, teacher, coding) - Multi-turn subagent conversations - Context injection from the parent conversation - System prompt configuration Meanwhile, `ask_teacher` is a separate hardcoded escalation path in `src/teacher_escalation.py` that duplicates much of this logic. ## What I Want A unified **subagent tool** that replaces both `chat_with_model` and the ad-hoc teacher escalation with a configurable, role-aware subagent system: ### Default Behavior ``` User: "Write a Python function to sort a list" Agent: [calls subagent tool with default model, inherits conversation context] → Response from subagent using same model as parent ``` ### Role-Based Routing ``` User: "Ask the coder to implement this" Agent: [calls subagent tool with role=coding] → Uses the coding_model from settings (see #922) User: "Ask the teacher for help" Agent: [calls subagent tool with role=teacher] → Uses the teacher_model from settings ``` ### Explicit Model Override ``` User: "What would GPT-4 say about this?" Agent: [calls subagent with model=gpt-4] → Resolves model name to endpoint ``` ## Proposed Design ### Settings (depends on #922) - `default_model` — same as current - `coding_model` / `coding_endpoint_id` — for coding role - `teacher_model` — for teacher role (already exists) - Subagent inherits parent model by default ### Tool Schema ```json { "name": "subagent", "parameters": { "task": "Description of what to accomplish", "role": "default | coding | teacher | <model_name>", "context": "Optional extra context to inject", "system_prompt": "Optional system prompt override", "max_turns": 1 } } ``` ### Implementation Notes - `role=default` → uses the same model/endpoint as the parent conversation - `role=coding` → resolves to `coding_model` + `coding_endpoint_id` - `role=teacher` → resolves to `teacher_model` (replaces `ask_teacher` escalation) - `role=<model_name>` → resolves via `_endpoint_model_from_cache` (current `chat_with_model` behavior) - Single-turn by default (`max_turns=1`), but supports multi-turn if needed - Inherits parent conversation context (last N messages) for continuity ### Migration - Keep `chat_with_model` as a thin alias that calls `subagent(role=<resolved_model>)` for backward compatibility - Keep `ask_teacher` as an alias for `subagent(role=teacher)` - Tool name map already has aliases: `ask_model → chat_with_model`, `chat_model → chat_with_model` ### Files to Change - `src/ai_interaction.py` — rewrite `do_chat_with_model` into `do_subagent` - `src/teacher_escalation.py` — route `ask_teacher` through subagent - `src/tool_metadata.py` — update descriptions - `src/tool_name_map.py` — add `subagent → subagent`, `delegate → subagent` - `src/settings.py` — add coding model keys - `routes/` — any settings UI changes for model role config ## Related - #921 — Settings persistence (must be fixed first) - #922 — Coding model setting (prerequisite) - #590 — Autoresearch as agent tool (related but separate feature)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sleepy/odysseus#924
No description provided.