"""The capabilities supplied to a user Agent factory inside its child process."""fromtypingimportAny,Callable,Iterable,Protocol,Sequence,TypedDict,Union,TYPE_CHECKINGfromtypesimportMappingProxyTypefromsim_platform.domain.json_valuesimportcopy_jsonfromsim_platform.agents.carrier.taskimportTaskfromsim_platform.agents.tools.protocol.errorsimportToolErrorfromsim_platform.agents.tools.client.baseimportPlatformTool,ToolifTYPE_CHECKING:fromsim_platform.agents.carrier.modelimportToolCallclassAgentSettings(TypedDict):"""Detached per-run configuration, without credential values or App objects."""initial_prompt:strparameters:dictgranted_tools:listlimits:dictsymbol:strclassTaskClient(Protocol):"""The Agent process's work client: waits for tasks and reports Stop."""@propertydefstopping(self)->bool:...defnext_task(self,instruction:str)->Task:...classAgentModel(Protocol):"""A model adapter that turns a conversation and tools into tool calls."""defrespond(self,conversation:Any,tools:Sequence[Tool])->Sequence['ToolCall']:"""Return tool calls; network IO is performed in the Agent process."""...
[docs]classScheduledAgent(Protocol):"""An Agent the platform calls once per scheduled task."""
[docs]defrun(self,task:Task)->Any:"""Perform one scheduled task; use a platform finish/wait tool to end it."""...
[docs]classResidentAgent(Protocol):"""An Agent that runs its own loop and asks for tasks itself."""
[docs]defrun(self)->None:"""Own the loop, obtaining work with context.next_task() before using capabilities."""...
[docs]classAgentContext:"""Configure an Agent without exposing App objects, database or market readers. model is a lazy model adapter. tools maps granted platform names to remote Tool objects. Add your own Tool instances to the Agent's tool list; they run locally and are never added to the platform's operation registry. """def__init__(self,client:TaskClient,model:AgentModel,tools:Iterable[PlatformTool],settings:AgentSettings,)->None:self._client=clientself.model=modelself.tools=MappingProxyType({tool.name:toolfortoolintools})self._settings=copy_json(settings)@propertydefsettings(self)->AgentSettings:"""Return a detached copy of prompt, Agent parameters and granted bounds."""returncopy_json(self._settings)
[docs]deftool(self,name:str)->PlatformTool:"""Find a granted platform proxy; unknown or ungranted names fail clearly."""try:returnself.tools[name]exceptKeyErrorasexc:raiseToolError('TOOL_UNAVAILABLE','platform tool is not granted or provided: '+name)fromexc
[docs]defnext_task(self,instruction:str)->Task:"""Wait for Runtime work; valid only after Play, including for resident Agents."""returnself._client.next_task(instruction)