3333 _CUSTOM_SOFTWARE_SECTION ,
3434 _SKILLS_SECTION ,
3535 _SKILL_ENTRY_TEMPLATE ,
36+ _DEFAULT_ROLE_DESCRIPTION ,
3637)
3738from BaseAgent .resources import Skill
39+ from BaseAgent .agent_spec import AgentSpec
3840from BaseAgent .config import default_config
3941from BaseAgent .resource_manager import ResourceManager
4042from BaseAgent .retriever import ToolRetriever
@@ -61,6 +63,7 @@ def __init__(
6163 checkpoint_db_path : str | None = None ,
6264 require_approval : str | None = None ,
6365 skills_directory : str | None = None ,
66+ spec : AgentSpec | None = None ,
6467 ):
6568 """
6669 Args:
@@ -77,10 +80,27 @@ def __init__(
7780 "always" — interrupt before every code block;
7881 "dangerous_only" — interrupt only for bash/R code.
7982 skills_directory: Path to a directory of SKILL.md files to load on startup.
83+ spec: Optional agent identity and persona. When provided, ``spec.name``,
84+ ``spec.role``, ``spec.tool_names``, ``spec.skill_names``,
85+ ``spec.llm``, ``spec.source``, and ``spec.temperature`` override
86+ the corresponding defaults. Explicit keyword arguments take
87+ priority over spec fields.
8088 """
89+ self .spec = spec
90+
91+ # Agent name: from spec, or default
92+ self .name : str = spec .name if spec is not None else "agent"
93+
94+ # Resolve settings: explicit kwargs > spec > default_config
8195 self .path = path if path is not None else default_config .path
82- self .llm_model_name = llm if llm is not None else default_config .llm
83- self .source = source if source is not None else default_config .source
96+ self .llm_model_name = (
97+ llm if llm is not None
98+ else (spec .llm if spec is not None and spec .llm is not None else default_config .llm )
99+ )
100+ self .source = (
101+ source if source is not None
102+ else (spec .source if spec is not None and spec .source is not None else default_config .source )
103+ )
84104 self .timeout_seconds = timeout_seconds if timeout_seconds is not None else default_config .timeout_seconds
85105 self .base_url = base_url if base_url is not None else default_config .base_url
86106 self .api_key = api_key if api_key is not None else default_config .api_key
@@ -96,6 +116,13 @@ def __init__(
96116 #TODO: add self-critic mode
97117 self .self_critic = False
98118
119+ # Temperature: explicit kwarg not exposed yet, so spec takes precedence over default
120+ _temperature = (
121+ spec .temperature
122+ if spec is not None and spec .temperature is not None
123+ else default_config .temperature
124+ )
125+
99126 # Initialize the LLM agent
100127 self .source , self .llm = get_llm (
101128 self .llm_model_name ,
@@ -104,6 +131,7 @@ def __init__(
104131 base_url = self .base_url ,
105132 api_key = self .api_key ,
106133 config = default_config ,
134+ temperature = _temperature ,
107135 )
108136
109137 # Initialize the resource manager (replaces ToolRegistry)
@@ -694,9 +722,20 @@ def _generate_system_prompt(
694722 When tool retriever is not used, all resources have selected=True by default.
695723 When tool retriever is used, only retrieved resources are marked selected=True.
696724 """
725+ # If the spec provides a full override, return it directly
726+ if self .spec is not None and self .spec .system_prompt_override is not None :
727+ return self .spec .system_prompt_override
728+
697729 # Base prompt
698730 prompt_modifier = get_base_prompt_template (self_critic = self_critic )
699- prompt_format_dict = {}
731+
732+ # Role description: from spec, or fall back to the default
733+ role_description = (
734+ self .spec .role
735+ if self .spec is not None
736+ else _DEFAULT_ROLE_DESCRIPTION
737+ )
738+ prompt_format_dict = {"role_description" : role_description }
700739
701740 # Add custom resources section from resource manager
702741 custom_tools = self .resource_manager .collection .custom_tools
@@ -825,6 +864,13 @@ def configure(self, self_critic=False, test_time_scale_round=0):
825864 if self .skills_directory :
826865 self .load_skills (self .skills_directory )
827866
867+ # Apply AgentSpec resource filters (must happen after resources are loaded)
868+ if self .spec is not None :
869+ if self .spec .tool_names is not None :
870+ self .resource_manager .select_tools_by_names (self .spec .tool_names )
871+ if self .spec .skill_names is not None :
872+ self .resource_manager .select_skills_by_names (self .spec .skill_names )
873+
828874 # Generate the system prompt (will be built automatically from ResourceManager)
829875 self .system_prompt = self ._generate_system_prompt (
830876 self_critic = self_critic ,
0 commit comments