# 963 Agent Model Display Fixes C7db7d68

> Agent Model and Display Name Fixes

- Skill: `tools-only/963-agent-model-display-fixes-c7db7d68` (Agent Skill, multi-file: 3 files)
- Install (CLI): `npx skillmds@latest add tools-only/963-agent-model-display-fixes-c7db7d68`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tools-only/963-agent-model-display-fixes-c7db7d68/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: tools-only (https://skillmd.com/u/tools-only)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/tools-only/963-agent-model-display-fixes-c7db7d68

---

# Agent Model and Display Name Fixes

**Version Implemented:** 0.229.001

## Summary
Fixed UX issues with message metadata and display when using Semantic Kernel agents.

## Issues Fixed

### 1. Model Selection in Message Metadata ✅
**Problem**: Messages showed the fallback model (gpt-5-chat) even when using agents with different models.

**Example**: World News Agent uses `gpt-4o` but messages showed `model_deployment_name: "gpt-5-chat"`

**Fix**: 
- Modified `route_backend_chats.py` to use agent's actual model when available
- Added logic to extract `deployment_name` from `selected_agent` object
- Falls back to `final_model_used` when no agent is selected

**Code Changes**:
```python
# Determine the actual model used and agent information
actual_model_used = final_model_used
if selected_agent:
    # When using an agent, use the agent's actual model deployment
    if hasattr(selected_agent, 'deployment_name') and selected_agent.deployment_name:
        actual_model_used = selected_agent.deployment_name
```

### 2. Message Sender Display ✅
**Problem**: Messages showed "AI (gpt-4o)" even when using named agents like "World News Agent".

**Expected**: 
- With agents: Show agent display name (e.g., "World News Agent")
- Without agents: Show "AI (model-name)" format

**Fix**: 
- Added `agent_display_name` and `agent_name` to backend response
- Modified frontend `appendMessage` function to use agent display name when available
- Updated all `appendMessage` calls to include new parameters

**Code Changes**:
```javascript
// Frontend logic in chat-messages.js
if (agentDisplayName) {
  senderLabel = agentDisplayName;
} else if (modelName) {
  senderLabel = `AI <span style="color: #6c757d; font-size: 0.8em;">(${modelName})</span>`;
} else {
  senderLabel = "AI";
}
```

### 3. UI Model Selection Metadata ✅ NEW FIX
**Problem**: The "Selected Model" in the UI metadata panel showed fallback model instead of agent's model.

**Example**: UI showed "Selected Model: gpt-5-chat" even when World News Agent (gpt-4o) was being used.

**Fix**: 
- Added logic to update user message metadata after agent model is determined
- Updates the `model_selection.selected_model` field to reflect actual model used
- Ensures UI consistency between agent selection and model display

**Code Changes**:
```python
# Update the user message metadata with the actual model used
try:
    user_message_doc = cosmos_messages_container.read_item(
        item=user_message_id, 
        partition_key=conversation_id
    )
    
    # Update the model selection in metadata to show actual model used
    if 'metadata' in user_message_doc and 'model_selection' in user_message_doc['metadata']:
        user_message_doc['metadata']['model_selection']['selected_model'] = actual_model_used
        cosmos_messages_container.upsert_item(user_message_doc)
        
except Exception as e:
    print(f"Warning: Could not update user message metadata: {e}")
```

## Files Modified

### Backend
- `route_backend_chats.py`: Added agent model extraction and metadata update logic
- `config.py`: Updated version to 0.226.078

### Frontend  
- `static/js/chat/chat-messages.js`: Updated `appendMessage` function and all call sites

## Testing
- `functional_tests/test_agent_model_display_fixes.py`: Validates message display logic
- `functional_tests/test_model_selection_metadata_fix.py`: Validates UI metadata consistency

## Result
✅ **Agent messages**: Show agent display name and correct model  
✅ **Non-agent messages**: Show "AI (model)" format as before  
✅ **Message metadata**: Contains accurate model and agent information  
✅ **UI metadata panel**: Shows consistent agent model information  
✅ **Backward compatibility**: Existing functionality preserved  

## Example Behavior

### Before Fixes
```
Message from World News Agent:
- Sender: "AI (gpt-5-chat)"  ❌ Wrong model, generic sender
- Message Metadata: model_deployment_name: "gpt-5-chat"  ❌ Fallback model
- UI Metadata Panel: "Selected Model: gpt-5-chat"  ❌ Inconsistent with agent
```

### After Fixes  
```
Message from World News Agent:
- Sender: "World News Agent"  ✅ Agent display name
- Message Metadata: model_deployment_name: "gpt-4o"  ✅ Agent's actual model
- UI Metadata Panel: "Selected Model: gpt-4o"  ✅ Consistent with agent
```

## Impact
Users now see consistent, accurate information about which agent and model are being used, providing better transparency and user experience when working with AI agents.

