instrukt.agent.base.InstruktAgent

class instrukt.agent.base.InstruktAgent(*, id: str = None, llm: BaseChatModel, toolset: Sequence[SomeTool] = None, executor: AgentExecutor | None = None, realm: Any | None = None, state: AgentStateMachine[Any] = None, memory: BaseChatMemory | None = None, executor_params: dict[str, Any] = None, llm_callback_handlers: list[langchain.callbacks.base.BaseCallbackHandler] = None)[source]

Bases: BaseModel, ABC

Instrukt agents need to satisfy this base class.

defining a custom agent
class MyAgent(InstruktAgent):
    name = "my_agent"
    description = "my agent description"

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param executor: AgentExecutor | None = None
param executor_params: dict[str, Any] [Optional]
param id: str [Optional]
param llm: BaseChatModel [Required]
param llm_callback_handlers: list[langchain.callbacks.base.BaseCallbackHandler] [Optional]

OpenAI callback handler for this agent.

param memory: BaseChatMemory | None [Optional]
param realm: Any | None = None
param state: AgentStateMachine[Any] [Optional]
param toolset: Sequence[SomeTool] [Optional]
add_tool(tool: SomeTool) None[source]

Add a tool to the agent.

async agent_running() bool[source]

Check if a task is running for this agent.

attach_tool(name: str) None[source]

Attach a tool to the agent.

dettach_tool(name: str) None[source]

Dettach a tool from the agent.

forget_about(term: str) None[source]

Removes all occurences of term from chat memory.

is_attached_tool(tool_name: str) bool[source]
abstract classmethod load(ctx: Context) InstruktAgent | None[source]

Agent loading logic goes here.

reload_agent() None[source]

Reloads the agent. Call this method after you modify the agent’s toolset.

async send_message(ctx: Context, msg: str) None[source]

Send a message to the agent (async).

async stop_agent(ctx: Context) bool[source]

Stop the agent task.

update_tool_name(old: str, new: str) None[source]

Change the name of an attached tool.

validator validate_executor_params  »  executor_params[source]

memory cannot be passed in executor_params as well as attribute.

property attached_tools: list[str]

Return the list of attached tools as str.

property base_agent: BaseSingleActionAgent | BaseMultiActionAgent | None

Return underlying agent (langchain).

description: ClassVar[str | None] = None
display_name: ClassVar[str | None] = None

Display name of the agent. Can contain spaces.

name: ClassVar[str | None] = None

Name of the agent. Must not contain spaces.

property openai_cb_handler: OpenAICallbackHandler | None
property toolset_names: list[str]

Return the names of the tools in toolset.

model Config[source]

Bases: object

arbitrary_types_allowed = True