Skip to content

refine response format#467

Merged
iceljc merged 2 commits into
SciSharp:mainfrom
iceljc:features/refine-response-format
Jun 24, 2026
Merged

refine response format#467
iceljc merged 2 commits into
SciSharp:mainfrom
iceljc:features/refine-response-format

Conversation

@iceljc

@iceljc iceljc commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Refine response_format handling by moving it into LLM config
✨ Enhancement 🐞 Bug fix 🕐 20-40 Minutes

Grey Divider

Description

• Move response_format from template root into llm_config for consistency.
• Add Response format selectors to chat and template LLM config editors.
• Update Agent type docs and adjust template config input sizing.
Diagram

graph TD
  A["Agent Template UI"] --> B["Template config (Svelte)"] --> C["template.llm_config.response_format"] --> D["ResponseFormat enum"]
  E["Chat config UI"] --> F["Chat config (Svelte)"] --> G["config.response_format"] --> D
  B --> H["Agent types (JSDoc)"]
  B --> I["Agent page styles"]

  subgraph Legend
    direction LR
    _ui[UI] ~~~ _state[(State/Config)] ~~~ _type[Types/Enums]
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Backward-compatible read/migrate of legacy template.response_format
  • ➕ Prevents breaking existing stored templates that still have response_format at the template root
  • ➕ Enables gradual rollout without requiring coordinated data cleanup
  • ➖ Adds temporary complexity and tech debt (needs later removal)
  • ➖ Requires deciding precedence when both fields exist
2. Centralize ResponseFormat select into a shared component
  • ➕ Avoids duplicating dropdown wiring/handlers across chat-config and template-config
  • ➕ Makes future option/label changes safer and more consistent
  • ➖ Small upfront refactor cost
  • ➖ May be overkill if only used in two places
3. Keep response_format at template root and map to llm_config only at save time
  • ➕ Minimizes schema changes and reduces migration risk
  • ➕ Keeps UI state flatter in template editing
  • ➖ Perpetuates ambiguity about the canonical source of LLM settings
  • ➖ Increases chance of drift between stored template and effective llm_config

Recommendation: The PR’s direction (making response_format part of llm_config) is the cleanest long-term model because response_format is an LLM/runtime concern. However, removing template.response_format mapping in agent-template.svelte can break older saved templates. Consider adding a temporary compatibility layer (read legacy template.response_format and write it into llm_config on load, then persist in the new location) and/or a one-time migration, then remove it later.

Files changed (5) +55 / -24

Enhancement (2) +36 / -2
_agent.scssImprove template config input sizing/box model +2/-0

Improve template config input sizing/box model

• Adds a fixed height and border-box sizing to .tplc-input to stabilize layout and padding behavior.

src/lib/styles/pages/_agent.scss

chat-config.svelteAdd response_format selection to chat LLM config +34/-2

Add response_format selection to chat LLM config

• Extends chat config initialization to include response_format, builds dropdown options from ResponseFormat, and adds a new Select field that persists changes via handleAgentChange().

src/routes/page/agent/[agentId]/agent-components/llm-configs/chat-config.svelte

Bug fix (1) +0 / -2
agent-template.svelteStop reading/writing response_format at template root +0/-2

Stop reading/writing response_format at template root

• Removes response_format from template normalization and instance creation logic, making llm_config the only remaining place for response format to live.

src/routes/page/agent/[agentId]/agent-components/templates/agent-template.svelte

Refactor (2) +19 / -20
agentTypes.jsDocument response_format as part of LLM config types +3/-2

Document response_format as part of LLM config types

• Removes response_format from the top-level AgentTemplate doc and adds it to the relevant config typedefs (including AgentTemplateConfig). Also normalizes minor formatting (provider property spacing).

src/lib/helpers/types/agentTypes.js

agent-template-config.svelteMove template response_format UI under LLM Configuration +16/-18

Move template response_format UI under LLM Configuration

• Changes the response format handler to write into template.llm_config.response_format (creating llm_config if missing) and relocates the Response format selector from the general template section into the LLM Configuration section.

src/routes/page/agent/[agentId]/agent-components/templates/agent-template-config.svelte

ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Template config shadows agent 🐞 Bug ≡ Correctness
Description
changeResponseFormat() now creates template.llm_config = { provider: null, model: null } just to
store response_format, making template.llm_config truthy even when the template should otherwise
inherit agent settings. Downstream, InstructionAgent prefers selectedTemplate.llm_config over
selectedAgent.llm_config, which can clear provider/model and break LLM selection for that
template.
Code

src/routes/page/agent/[agentId]/agent-components/templates/agent-template-config.svelte[R91-97]

    function changeResponseFormat(e) {
        const value = e?.detail?.selecteds?.map((/** @type {any} */ x) => x.value)[0] || null;
-        template.response_format = value;
+        if (!template.llm_config) {
+            template.llm_config = { provider: null, model: null };
+        }
+        template.llm_config.response_format = value;
        handleAgentChange();
Evidence
The PR change creates a non-null template llm_config with null provider/model when setting response
format, while the instruction testing flow selects template.llm_config preferentially and then reads
provider/model directly from it, causing those values to become null.

src/routes/page/agent/[agentId]/agent-components/templates/agent-template-config.svelte[90-98]
src/routes/page/instruction/instruction-components/instruction-agent.svelte[37-69]
src/routes/page/instruction/testing/+page.svelte[178-197]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Setting a template response format creates a non-null `template.llm_config` with `provider/model = null`, and other screens treat `template.llm_config` as a complete override (not a partial overlay). This causes agent-level provider/model to be lost when selecting that template.

## Issue Context
- `InstructionAgent` currently computes `llmConfig` via `selectedTemplate?.llm_config || selectedAgent?.llm_config`, so any non-null template config wins, even if it only contains `response_format`.

## Fix Focus Areas
- src/routes/page/agent/[agentId]/agent-components/templates/agent-template-config.svelte[91-97]
- src/routes/page/instruction/instruction-components/instruction-agent.svelte[37-69]

## Recommended fix
Pick one of these (prefer 1 or 2):
1) **Treat template.llm_config as a partial override** in `InstructionAgent` by merging:
  - Start from `selectedAgent.llm_config`
  - Overlay only non-null/non-undefined fields from `selectedTemplate.llm_config`
  - Ensure `provider/model` fall back to agent values when template values are null
2) **Don’t instantiate `template.llm_config` when only response_format is set**, unless the rest of the app supports partial-template configs everywhere. (E.g., store template response format separately, or only set `template.llm_config` when provider/model/max tokens/etc are configured.)
3) Add an explicit “inherit agent llm_config” behavior for templates, and ensure `response_format` can override without forcing provider/model overrides.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Legacy format not migrated 🐞 Bug ☼ Reliability
Description
Template serialization/deserialization now ignores the legacy top-level template.response_format
field and only preserves template.llm_config. Any existing agents (or imported JSON) that still
store response format at the template root will silently lose it on edit/save unless it’s migrated
into template.llm_config.response_format.
Code

src/routes/page/agent/[agentId]/agent-components/templates/agent-template.svelte[R45-49]

            return {
                name: x.name.trim().toLowerCase(),
                content: x.content,
-                response_format: x.response_format || null,
                llm_config: llmConfig
            };
Evidence
Template save/init code now only carries llm_config and the types/UI bind response format under
llm_config, so any existing root-level response_format will not be displayed nor re-saved by the
editor.

src/routes/page/agent/[agentId]/agent-components/templates/agent-template.svelte[39-50]
src/routes/page/agent/[agentId]/agent-components/templates/agent-template.svelte[74-82]
src/lib/helpers/types/agentTypes.js[6-12]
src/routes/page/agent/[agentId]/agent-components/templates/agent-template-config.svelte[237-246]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The UI no longer reads/writes `template.response_format` (legacy schema) and instead uses `template.llm_config.response_format`. Without a migration step, legacy data will have its response format dropped when the agent is edited and saved.

## Issue Context
- Import flow saves arbitrary JSON as-is.
- Template editor now initializes and saves templates without a top-level `response_format`.

## Fix Focus Areas
- src/routes/page/agent/[agentId]/agent-components/templates/agent-template.svelte[39-50]
- src/routes/page/agent/[agentId]/agent-components/templates/agent-template.svelte[74-82]
- src/routes/page/agent/[agentId]/agent-components/templates/agent-template-config.svelte[237-246]

## Recommended fix
Add a compatibility/migration layer when loading templates (and/or when importing agents):
- If a template has `response_format` at the root and `llm_config.response_format` is missing:
 - Create `llm_config` if needed
 - Move/copy `response_format` into `llm_config.response_format`
- Optionally (during a transition period), when saving/exporting templates, also emit the legacy `response_format` field for backward compatibility with older consumers.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan

Qodo Logo

Comment on lines 91 to 97
function changeResponseFormat(e) {
const value = e?.detail?.selecteds?.map((/** @type {any} */ x) => x.value)[0] || null;
template.response_format = value;
if (!template.llm_config) {
template.llm_config = { provider: null, model: null };
}
template.llm_config.response_format = value;
handleAgentChange();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Template config shadows agent 🐞 Bug ≡ Correctness

changeResponseFormat() now creates template.llm_config = { provider: null, model: null } just to
store response_format, making template.llm_config truthy even when the template should otherwise
inherit agent settings. Downstream, InstructionAgent prefers selectedTemplate.llm_config over
selectedAgent.llm_config, which can clear provider/model and break LLM selection for that
template.
Agent Prompt
## Issue description
Setting a template response format creates a non-null `template.llm_config` with `provider/model = null`, and other screens treat `template.llm_config` as a complete override (not a partial overlay). This causes agent-level provider/model to be lost when selecting that template.

## Issue Context
- `InstructionAgent` currently computes `llmConfig` via `selectedTemplate?.llm_config || selectedAgent?.llm_config`, so any non-null template config wins, even if it only contains `response_format`.

## Fix Focus Areas
- src/routes/page/agent/[agentId]/agent-components/templates/agent-template-config.svelte[91-97]
- src/routes/page/instruction/instruction-components/instruction-agent.svelte[37-69]

## Recommended fix
Pick one of these (prefer 1 or 2):
1) **Treat template.llm_config as a partial override** in `InstructionAgent` by merging:
   - Start from `selectedAgent.llm_config`
   - Overlay only non-null/non-undefined fields from `selectedTemplate.llm_config`
   - Ensure `provider/model` fall back to agent values when template values are null
2) **Don’t instantiate `template.llm_config` when only response_format is set**, unless the rest of the app supports partial-template configs everywhere. (E.g., store template response format separately, or only set `template.llm_config` when provider/model/max tokens/etc are configured.)
3) Add an explicit “inherit agent llm_config” behavior for templates, and ensure `response_format` can override without forcing provider/model overrides.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@iceljc iceljc merged commit e0aae7f into SciSharp:main Jun 24, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant