Agent that can perform tasks using tools and LLMs.
| Method | __del__ |
Cleanup resources on deletion. |
| Method | __init__ |
Initialize the agent with a mode, LLM, and request file path. |
| Method | close |
Close the agent and stop any running tasks. |
| Method | run |
Run the agent for a prompt and return the response text. |
| Method | run |
Run the agent with a JSON payload and return a structured response. |
| Method | run |
Run the agent with a session ID and user message, returning a structured response. |
| Method | run |
Start a session on another thread. |
| Class Variable | __slots__ |
Undocumented |
| Instance Variable | http |
Undocumented |
| Instance Variable | llm |
Undocumented |
| Instance Variable | mode |
Undocumented |
| Instance Variable | tools |
Undocumented |
| Instance Variable | view |
Undocumented |
| Property | file |
Get the file path associated with the agent. |
| Property | in |
Check if the agent is currently running a task. |
| Property | response |
Get the latest response from the agent. |
| Static Method | _json |
Escape a string for embedding in JSON. |
| Static Method | _mcp |
Create a unique model-safe name for an MCP tool. |
| Static Method | _sanitize |
Replace characters unsupported by common tool-name schemas. |
| Static Method | _stream |
Stream a file to the destination with JSON escaping. |
| Method | _build |
Stream the conversation and metadata into the API request file. |
| Method | _build |
Build built-in and currently selected MCP tool schemas. |
| Method | _conv |
Append one message to the conversation file. |
| Method | _conv |
Write the initial conversation messages to the conversation file. |
| Method | _execute |
Execute a built-in or selected MCP tool. |
| Method | _parse |
Parse tool-call arguments defensively into a dict. |
| Method | _run |
Run the model/tool loop until a final reply is produced. |
| Method | _sanitize |
Normalize history to user and assistant text messages only. |
| Method | _select |
Select an MCP server and expose its discovered tools. |
| Method | _should |
Check if the request should continue running. |
| Method | _store |
Store the latest response for the caller to pick up. |
| Method | _write |
Write the system message to the conversation file. |
| Instance Variable | _conv |
Undocumented |
| Instance Variable | _current |
Undocumented |
| Instance Variable | _file |
Undocumented |
| Instance Variable | _lock |
Undocumented |
| Instance Variable | _mcp |
Undocumented |
| Instance Variable | _mcp |
Undocumented |
| Instance Variable | _mcp |
Undocumented |
| Instance Variable | _mem |
Undocumented |
| Instance Variable | _msg |
Undocumented |
| Instance Variable | _response |
Undocumented |
| Instance Variable | _running |
Undocumented |
int = MODE_CHAT, llm: LLM = None, file_path: str = 'picoware/settings/agent_request.json'):
¶
Initialize the agent with a mode, LLM, and request file path.
| Parameters | |
viewViewManager | The view manager for storage and threading. |
mode:int | The agent mode constant. Defaults to MODE_CHAT. |
llm:LLM | The LLM client to use. Defaults to None. |
filestr | Path to the API request file. Defaults to "picoware/settings/agent_request.json". |
Run the agent for a prompt and return the response text.
| Parameters | |
topic:str | The user prompt. |
conversation:list[dict] or None | Prior message history. Defaults to None. |
context:str or None | Extra context prepended to the system prompt. Defaults to None. |
| Returns | |
str | The assistant response text, or an error message. |
Run the agent with a JSON payload and return a structured response.
| Parameters | |
payload:dict | The request payload with message and conversation keys. |
| Returns | |
dict | The response with status, message, and conversation keys. |
Run the agent with a session ID and user message, returning a structured response.
| Parameters | |
sessionstr | The unique identifier for the session. |
userstr | The user's message to process. |
| Returns | |
dict | The response with status, message, and conversation keys. |
Start a session on another thread.
The session result is available from the response property once in_progress returns False.
| Parameters | |
sessionstr | The unique identifier for the session. |
userstr | The user's message to process. |
| Returns | |
bool | True if the session was successfully started, False otherwise. |
Get the latest response from the agent.
| Returns | |
str | dict | None |
|
Escape a string for embedding in JSON.
| Parameters | |
text:str | The raw string to escape. |
| Returns | |
str | The JSON-escaped string. |
Stream a file to the destination with JSON escaping.
| Parameters | |
storage:Storage | The storage interface. |
srcstr | The source file path. |
dststr | The destination file path. |
Stream the conversation and metadata into the API request file.
| Parameters | |
tools:list[dict] | The tool schemas to include in the request. |
Write the initial conversation messages to the conversation file.
| Parameters | |
messages:list[dict] | The initial messages to store. |
Parse tool-call arguments defensively into a dict.
| Parameters | |
rawstr or dict | Raw arguments from the model call. |
| Returns | |
dict | The parsed arguments, or an empty dict if unparseable. |
Run the model/tool loop until a final reply is produced.
| Returns | |
str | The final assistant text, or an error message. |
list[ dict] | None, max_messages: int = MAX_CONVERSATION_MESSAGES) -> list[ dict[ str, str]]:
¶
Store the latest response for the caller to pick up.
| Parameters | |
response:str or dict | The response to store. |
done:bool | Clear the running flag when True. Defaults to False. |