-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(projects): per-project default agent selection #1834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e0f2ce2
5235d4d
d9123cc
84faa3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -399,6 +399,19 @@ def _get_projects_list(parent_dir): | |
| return projects | ||
|
|
||
|
|
||
| def get_project_default_agent(name: str | None) -> str | None: | ||
| """Return the project's preferred default agent profile, or None.""" | ||
| if not name: | ||
| return None | ||
| try: | ||
| abs_path = files.get_abs_path(get_project_meta(name), "default_agent.json") | ||
| data = dirty_json.parse(files.read_file(abs_path)) | ||
| agent = str(data.get("agent", "") or "").strip() if isinstance(data, dict) else "" | ||
| return agent or None | ||
| except Exception: | ||
| return None | ||
|
|
||
|
|
||
| def reconcile_agent_profile( | ||
| context: "AgentContext", project_name: str | None, available: dict | None = None | ||
| ) -> bool: | ||
|
|
@@ -408,11 +421,42 @@ def reconcile_agent_profile( | |
| if available is None: | ||
| available = subagents.get_available_agents_dict(project_name) | ||
| if getattr(context.config, "profile", "") in available: | ||
| # project default agent: switch only when the context still runs the | ||
| # global default (i.e. no explicit per-chat selection has been made) | ||
| manually_set = context.get_data("agent_profile_manually_set") | ||
| default_agent = get_project_default_agent(project_name) | ||
| if ( | ||
| not manually_set | ||
|
Comment on lines
+426
to
+429
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Fresh evidence after the earlier review fix: only Useful? React with 👍 / 👎. |
||
| and default_agent | ||
| and default_agent in available | ||
| and default_agent != getattr(context.config, "profile", "") | ||
| ): | ||
| from helpers import settings as settings_helper | ||
|
|
||
| global_default = settings_helper.get_settings().get("agent_profile", "") | ||
| if getattr(context.config, "profile", "") == global_default: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a project default is configured and the user explicitly selects the global profile in that project, any later reconciliation sweep (for example project reactivation or agent availability changes) satisfies this equality and replaces that selection with Useful? React with 👍 / 👎. |
||
| config = initialize_agent( | ||
| override_settings={"agent_profile": default_agent} | ||
| ) | ||
| context.config = config | ||
| context.agent0.config = config | ||
| return True | ||
| return False | ||
|
|
||
| config = initialize_agent() | ||
| if config.profile not in available: | ||
| fallback = "agent0" if "agent0" in available else next(iter(available), "agent0") | ||
| default_agent = get_project_default_agent(project_name) | ||
| if config.profile not in available or ( | ||
| default_agent | ||
| and default_agent in available | ||
| and config.profile != default_agent | ||
| ): | ||
| fallback = ( | ||
| default_agent | ||
| if default_agent in available | ||
| else "agent0" | ||
| if "agent0" in available | ||
| else next(iter(available), "agent0") | ||
| ) | ||
| config = initialize_agent(override_settings={"agent_profile": fallback}) | ||
| context.config = config | ||
| context.agent0.config = config | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a project has
.a0proj/default_agent.jsonand a user explicitly changes that chat back to the global profile from the Telegram inline agent picker,plugins/_telegram_integration/helpers/command_ui.py:423-426still updatescontext.config/context.agent0.configand saves without writingagent_profile_manually_set. Because this new guard treats the missing flag as an implicit default selection, the next activation or reconcile sweep sees the chat on the global default and silently switches it back to the project default, losing the Telegram selection. Fresh evidence after the earlier fixes:/agentand API paths were updated in this patch, but the Telegram picker still has the unflagged config swap.AGENTS.md reference: helpers/AGENTS.md:L15-L15
Useful? React with 👍 / 👎.