class documentation
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 | 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. |
| 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. |
| Static Method | _json |
Escape a string for embedding in JSON. |
| 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 | _conv |
Append one message to the conversation file. |
| Method | _conv |
Write the initial conversation messages to the conversation file. |
| 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 | _write |
Write the system message to the conversation file. |
| Instance Variable | _conv |
Undocumented |
| Instance Variable | _file |
Undocumented |
| Instance Variable | _mem |
Undocumented |
| Instance Variable | _msg |
Undocumented |
def __init__(self, view_manager, mode:
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. |
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. |
def _sanitize_conversation(self, conversation:
list[ dict] | None, max_messages: int = MAX_CONVERSATION_MESSAGES) -> list[ dict[ str, str]]:
¶