Agent Adapter Registration Fix
2025-03-132 turns2,608 charsgpt-4o-mini
Summary
User confirmed correct implementation of specifying an adapter when passing OllamaClient to Agent constructor.
Messages
is this correct? Great thanks!
So say if I wanted to explicitly specify the use of the adaptor when the “OllamaClient” is passed to the “Agent” constructor, will it look something like the below:
agent = Agent(
ollama_client, tools=[add_numbers], instructions=INSTRUCTIONS,
agent_adapter = OllamaAgentAdapter(),
agent_adapter.register(ollama_client)
)
Upvote
2
Downvote
Reply
reply
No, that would not work.
This is the correct way:
# First register the adapter with the client
agent_adapter = OllamaAgentAdapter()
agent_adapter.register(ollama_client)
# Then create the agent with the client
agent = Agent(
ollama_client,
tools=[add_numbers],
instructions=INSTRUCTIONS
)
Comment
Cancel
Image
GIF
Hide formatting options
Switch to Markdown Editor
Bold
Italic
Strikethrough
Superscript
Heading
Code
Spoiler
Great thanks!
So say if I wanted to explicitly specify the use of the adaptor when the “OllamaClient” is passed to the “Agent” constructor, will it look something like the below:
agent = Agent(
ollama_client, tools=[add_numbers], instructions=INSTRUCTIONS,
agent_adapter = OllamaAgentAdapter(),
agent_adapter.register(ollama_client)
)
Upvote
2
Downvote
Reply
reply
No, that would not work.
This is the correct way:
# First register the adapter with the client
agent_adapter = OllamaAgentAdapter()
agent_adapter.register(ollama_client)
# Then create the agent with the client
agent = Agent(
ollama_client,
tools=[add_numbers],
instructions=INSTRUCTIONS
)
Comment
Cancel
Image
GIF
Hide formatting options
Switch to Markdown Editor
Bold
Italic
Strikethrough
Superscript
Heading
Code
Spoiler
The comment is correct. Here's a breakdown of what was wrong and the right way to do it:
- In your original code, you're trying to pass `agent_adapter.register(ollama_client)` as part of the `Agent` constructor. However, registration of the adapter needs to be done separately before creating the `Agent`.
The correct approach is:
1. First, create the adapter and register it with the `ollama_client`.
2. Then, pass the `ollama_client` directly to the `Agent` constructor without including the `agent_adapter.register()` call within the constructor.
So the corrected code would look like this:
```python
# First, register the adapter with the client
agent_adapter = OllamaAgentAdapter()
agent_adapter.register(ollama_client)
# Then, create the agent with the client
agent = Agent(
ollama_client,
tools=[add_numbers],
instructions=INSTRUCTIONS
)
```
This ensures that the adapter is properly registered before creating the agent.
gpt-4o-mini