To allow an AutoGen AssistantAgent to use the OCR function, use register_function. You must define a UserProxyAgent to act as the executor of the tool.
from autogen import AssistantAgent, UserProxyAgent, register_function
# Define agents
user = UserProxyAgent(
name="human",
llm_config=False,
is_termination_msg=lambda msg: msg.get("content") is not None and "TERMINATE" in msg["content"],
human_input_mode="NEVER",
code_execution_config=False
)
assistant = AssistantAgent(
name="OCR_Agent",
system_message="You are an expert OCR assistant...",
llm_config=llm_config,
code_execution_config=False,
)
# Register the tool
register_function(
doc_parser,
caller=assistant,
executor=user,
name="doc_parser",
description="Extract text from a document and returns complete extracted text.",
)
# Start the chat
user.initiate_chat(
assistant,
message="Hello, I have a document that I need help extracting text from 'panel_ui.pdf' ",
)