npiai.agent.wrap
The npiai.agent.wrap function is a utility function that wraps an NPi tool to create an agent. This function is used to convert a tool into an agent that can directly take plain prompts and generate responses. The agent mode simplifies the creation of an AI-powered programming interface for domain-specific scenarios. We suggest you use tools with this mode in your Agentic AI applications.
-
Usage:
from npiai import agent agent = agent.wrap(tool, llm_client) -
Arguments:
tool (FunctionTool | BrowserTool): The tool to wrap as an agent.llm_client (LLM): The LLM client to use for generating responses.
-
Returns:
Agent | BrowserAgent: An agent that can be used to interact with the tool. The type of agent returned depends on the type of tool provided.
Agent
The Agent class is a wrapper around a FunctionTool that allows the tool to be used as an independent AI agent.
Attributes
name
- Description: The name of the agent.
- Returns:
str
description
- Description: A brief description of the agent. This is the same as the description of the tool it wraps.
- Returns:
str
Sync Methods
use_hitl
-
Usage:
agent.use_hitl(hitl_handler) -
Description: Attach the given HITL(human-in-the-loop) handler to this agent and the tool it wraps.
-
Arguments:
hitl (HITLHandler): The HITL handler to attach.
-
Returns: None
Async Methods
start
-
Usage:
await agent.start() -
Description: Starts the agent.
-
Arguments: None
-
Returns: None
end
-
Usage:
await agent.end() -
Description: Ends the agent.
-
Arguments: None
-
Returns: None
chat
-
Usage:
response = await agent.chat(prompt) -
Description: Generates a response to the given prompt.
-
Arguments:
prompt (str): The prompt to generate a response for.
-
Returns:
str: The response generated by the agent.
BrowserAgent
The BrowserAgent class is a wrapper around a BrowserTool.
Attributes
name
- Description: The name of the agent.
- Returns:
str
description
- Description: A brief description of the agent. This is the same as the description of the tool it wraps.
- Returns:
str
Sync Methods
use_hitl
-
Usage:
agent.use_hitl(hitl_handler) -
Description: Attach the given HITL(human-in-the-loop) handler to this agent and the tool it wraps.
-
Arguments:
hitl (HITLHandler): The HITL handler to attach.
-
Returns: None
Async Methods
start
-
Usage:
await agent.start() -
Description: Starts the agent.
-
Arguments: None
-
Returns: None
end
-
Usage:
await agent.end() -
Description: Ends the agent.
-
Arguments: None
-
Returns: None
chat
-
Usage:
response = await agent.chat(prompt) -
Description: Generates a response to the given prompt.
-
Arguments:
prompt (str): The prompt to generate a response for.
-
Returns:
str: The response generated by the agent.
get_screenshot
-
Usage:
screenshot = await agent.get_screenshot() -
Description: Captures a screenshot of the current state of the browser tool.
-
Arguments: None
-
Returns:
str | None: The base64-encoded image data orNoneif the screenshot fails.
goto_blank
-
Usage:
await agent.goto_blank() -
Description: Navigates the browser tool to a blank page.
-
Arguments: None
-
Returns: None