You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ERROR:root:An error occurred: Unable to generate pydantic-core schema for <class 'langchain_core.callbacks.manager.CallbackManagerForToolRun'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.
If you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.
For further information visit https://errors.pydantic.dev/2.11/u/schema-for-unknown-type
Traceback (most recent call last):
File "tests/tool_langchain.py", line 112, in <module>
asyncio.run(main())
File "/usr/lib/python3.12/asyncio/runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "tests/tool_langchain.py", line 80, in main
autogen_tool = LangChainToolAdapter(drive_tool)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/autogen_ext/tools/langchain/_langchain_adapter.py", line 175, in __init__
args_type = create_model(f"{name}Args", **fields) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/main.py", line 1772, in create_model
return meta(
^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 237, in __new__
complete_model_class(
File "venv/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 597, in complete_model_class
schema = gen_schema.generate_schema(cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 706, in generate_schema
schema = self._generate_schema_inner(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 984, in _generate_schema_inner
return self._model_schema(obj)
^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 817, in _model_schema
{k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()},
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1186, in _generate_md_field_schema
common_field = self._common_field_schema(name, field_info, decorators)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1352, in _common_field_schema
schema = self._apply_annotations(
^^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 2264, in _apply_annotations
schema = get_inner_schema(source_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_schema_generation_shared.py", line 83, in __call__
schema = self._handler(source_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 2246, in inner_handler
schema = self._generate_schema_inner(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 989, in _generate_schema_inner
return self.match_type(obj)
^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1103, in match_type
return self._match_generic_type(obj, origin)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1126, in _match_generic_type
return self._union_schema(obj)
^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1414, in _union_schema
choices.append(self.generate_schema(arg))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 706, in generate_schema
schema = self._generate_schema_inner(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 989, in _generate_schema_inner
return self.match_type(obj)
^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 1107, in match_type
return self._unknown_type_schema(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 634, in _unknown_type_schema
raise PydanticSchemaGenerationError(
pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'langchain_core.callbacks.manager.CallbackManagerForToolRun'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.
If you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.
For further information visit https://errors.pydantic.dev/2.11/u/schema-for-unknown-type
To Reproduce
importasyncioimportosfromautogen_ext.tools.langchainimportLangChainToolAdapterfromautogen_ext.models.openaiimportOpenAIChatCompletionClientfromautogen_agentchat.messagesimportTextMessagefromautogen_agentchat.agentsimportAssistantAgentfromautogen_agentchat.uiimportConsolefromautogen_coreimportCancellationTokenfromgoogle.oauth2importservice_accountfromlangchain_googledrive.tools.google_drive.toolimportGoogleDriveSearchToolfromlangchain_googledrive.utilities.google_driveimportGoogleDriveAPIWrapperimportloggingasyncdefmain() ->None:
# Step 1: Authenticate with service accountSERVICE_ACCOUNT_FILE="./service-account.json"SCOPES= ["https://www.googleapis.com/auth/drive.readonly"]
try:
credentials=service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES
)
logging.info(f"Using service account: {credentials.service_account_email}")
# Initialize Google Drive API wrapperfolder_id="root"drive_wrapper=GoogleDriveAPIWrapper(
credentials=credentials,
folder_id=folder_id,
num_results=20,
template="gdrive-query-in-folder",
mode="documents-markdown"
)
# Create the Google Drive search tooldrive_tool=GoogleDriveSearchTool(api_wrapper=drive_wrapper)
print(drive_tool.invoke("my_docs"))
# # Wrap the LangChain tool with Autogen adapterautogen_tool=LangChainToolAdapter(drive_tool)
# Initialize the model clientmodel_client=OpenAIChatCompletionClient(
model="gpt-4",
api_key=os.getenv("OPENAI_API_KEY"),
model_config={"arbitrary_types_allowed": True}
)
# Create the assistant agent with the Google Drive toolagent=AssistantAgent(
"assistant",
tools=[autogen_tool],
model_client=model_client,
system_message="You can search for files in Google Drive using the provided tool."
)
awaitConsole(
agent.on_messages_stream(
[TextMessage(content="Tell me about the user", source="user")],
CancellationToken()
)
)
exceptExceptionase:
logging.error(f"An error occurred: {str(e)}")
raiseif__name__=="__main__":
logging.info("Starting Google Drive search tool")
asyncio.run(main())
logging.info("Done")
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
Which packages was the bug in?
Python Extensions (autogen-ext)
AutoGen library version.
Python 0.5.4
Other library version.
No response
Model used
gpt-4
Model provider
OpenAI
Other model provider
No response
Python version
3.12
.NET version
None
Operating system
Ubuntu
The text was updated successfully, but these errors were encountered:
ekzhu
changed the title
LangChainToolAdapter: GoogleDriveSearchTool
Error in LangChainToolAdapter GoogleDriveSearchTool: Unable to generate pydantic-core schema
Apr 25, 2025
What happened?
Describe the bug
The pytdantic-core schema seems to be failing with tools like GoogleDriveSearchTool. What am I missing here?
To Reproduce
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
Which packages was the bug in?
Python Extensions (autogen-ext)
AutoGen library version.
Python 0.5.4
Other library version.
No response
Model used
gpt-4
Model provider
OpenAI
Other model provider
No response
Python version
3.12
.NET version
None
Operating system
Ubuntu
The text was updated successfully, but these errors were encountered: