mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-11-01 19:30:53 +00:00
Remove the running-context guard from the agent profile endpoint and the switcher so a profile can be changed during an active monologue, matching chat model-preset overrides. Enable the switcher dropdown items while running by dropping the running gate from their disabled state; only the saving gate remains. The new profile applies to subsequent model turns and intentionally forfeits the prompt cache. Subordinate agents keep their own profile configs. Validation: 73 subagent profile tests passed including a new endpoint test that switches the profile while a real task is running; static regression tests guard against reintroducing the running guard in the endpoint, switcher mixin, and dropdown markup; node --check passed on the switcher mixin.
39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
from agent import AgentContext
|
|
from helpers import projects, subagents
|
|
from helpers.api import ApiHandler, Request, Response
|
|
from helpers.persist_chat import save_tmp_chat
|
|
from helpers.state_monitor_integration import mark_dirty_for_context
|
|
from initialize import initialize_agent
|
|
|
|
|
|
class SetAgentProfile(ApiHandler):
|
|
async def process(self, input: dict, request: Request) -> dict | Response:
|
|
context_id = str(input.get("context_id", "") or "").strip()
|
|
profile = str(input.get("agent_profile", "") or "").strip()
|
|
|
|
if not context_id:
|
|
return Response(status=400, response="Missing context_id")
|
|
if not profile:
|
|
return Response(status=400, response="Missing agent_profile")
|
|
|
|
context = AgentContext.get(context_id)
|
|
if not context:
|
|
return Response(status=404, response="Context not found")
|
|
profiles = subagents.get_available_agents_dict(
|
|
projects.get_context_project_name(context)
|
|
)
|
|
selected_profile = profiles.get(profile)
|
|
if selected_profile is None:
|
|
return Response(status=404, response=f"Agent profile '{profile}' not found")
|
|
|
|
config = initialize_agent(override_settings={"agent_profile": profile})
|
|
context.config = config
|
|
context.agent0.config = config
|
|
|
|
save_tmp_chat(context)
|
|
mark_dirty_for_context(context.id, reason="agent_profile_change")
|
|
return {
|
|
"ok": True,
|
|
"agent_profile": profile,
|
|
"agent_profile_label": selected_profile.title or profile,
|
|
}
|