Agent
The Agent resource provides a conversational interface with tool use. The agent can search knowledge, create facts, and manage memory—with optional approval workflows for write operations.
client.agent.invoke()POST /v1/agent/invokeSend a query to the agent and get a response with citations and optional pending actions.
Parameters
querystrRequiredThe user query to send to the agent.
group_idslist[str]RequiredGroup IDs the agent has access to for context.
user_rolestrOptionalDefault: "viewer"User role for permission checks: "viewer", "editor", or "admin".
auto_approveboolOptionalDefault: FalseIf True, automatically execute write operations without approval.
session_messageslist[dict]OptionalPrevious messages in this conversation session for context.
Returns
InvokeResponse with:
response: str- The agent's text responsecitations: list[Citation]- Facts used to generate the responsetool_trace: list[ToolTrace]- Record of tool calls madepending_actions: list[PendingAction]- Write operations awaiting approvalhas_pending_actions()- Check if approval is needed
Example
1from memoair import MemoAir23client = MemoAir()45# Ask the agent a question6response = client.agent.invoke(7 query="What projects is John working on?",8 group_ids=["user:john", "org:acme"],9)1011print(response.response)12# "Based on the knowledge graph, John is working on the following projects:13# 1. Project Alpha - a machine learning pipeline14# 2. Project Beta - API modernization"1516# Show citations17print("\nCitations:")18for citation in response.citations:19 print(f" - {citation.fact}")Approval Workflow
By default, write operations (creating facts, updating memory) require explicit approval. This prevents the agent from making unauthorized changes to your knowledge graph.
1from memoair import MemoAir23client = MemoAir()45# Ask the agent to remember something6response = client.agent.invoke(7 query="Remember that John just got promoted to Staff Engineer",8 group_ids=["user:john"],9 user_role="editor", # Has write permissions10)1112# Check for pending actions13if response.has_pending_actions():14 print("Agent wants to perform the following actions:")1516 for action in response.pending_actions:17 print(f"\n Tool: {action.tool_name}")18 print(f" Args: {action.tool_args}")19 print(f" Target: {action.target_graph}")2021 # Get user confirmation22 user_input = input("Approve? (y/n): ")2324 if user_input.lower() == 'y':25 result = client.agent.approve_action(26 action=action,27 group_ids=["user:john"],28 )29 print(f" Result: {result.result}")30 else:31 print(" Skipped")client.agent.execute_action()POST /v1/agent/executeExecute a pending action directly. Lower-level than approve_action().
Parameters
action_idstrRequiredUnique ID of the action to execute.
tool_namestrRequiredName of the tool to execute.
tool_argsdictRequiredArguments to pass to the tool.
target_graphstrRequiredWhich graph the action affects.
group_idslist[str]RequiredGroup IDs for context.
1# Execute an action directly2result = client.agent.execute_action(3 action_id=action.action_id,4 tool_name=action.tool_name,5 tool_args=action.tool_args,6 target_graph=action.target_graph,7 group_ids=["user:john"],8)910print(f"Executed: {result.result}")client.agent.approve_action()POST /v1/agent/approveConvenience wrapper to approve and execute a PendingAction.
1# Approve and execute a pending action2for action in response.pending_actions:3 result = client.agent.approve_action(4 action=action, # Pass the PendingAction object directly5 group_ids=["user:john"],6 )7 print(f"Approved: {result.result}")Auto-Approve Mode
For trusted automation scenarios, you can enable auto-approval to let the agent execute write operations immediately.
Warning: Use auto_approve=True with caution. The agent will create and modify facts without confirmation.
1# Auto-approve mode (use with caution)2response = client.agent.invoke(3 query="Add a note that John prefers morning meetings",4 group_ids=["user:john"],5 user_role="admin",6 auto_approve=True, # No confirmation needed7)89# The action was already executed10print(response.response)11# "I've added to John's preferences that he prefers morning meetings."Session Context
For multi-turn conversations, pass previous messages to maintain context:
1# Multi-turn conversation2session = []34# Turn 15response1 = client.agent.invoke(6 query="Who is John?",7 group_ids=["user:john"],8 session_messages=session,9)10session.append({"role": "user", "content": "Who is John?"})11session.append({"role": "assistant", "content": response1.response})1213# Turn 2 (with context)14response2 = client.agent.invoke(15 query="What projects is he working on?", # "he" refers to John16 group_ids=["user:john"],17 session_messages=session,18)19print(response2.response)