Getting error: AttributeError: 'str' object has no attribute 'id'

I am trying to create a simple custom function and calling from agent as part of tools getting below error:

PS C:\learn\HuggingFace> python .\OCI_IAM_AI_LLAMA.py
DEBUG Debug logs enabled
DEBUG *********** Agent Run Start: ed586dc7-16cc-477c-9956-ce17e1def0b3 ***********
DEBUG Function sum added to model.
DEBUG ---------- HuggingFace Response Start ----------
DEBUG ============== system ==============
DEBUG ## Instructions
Use markdown to format your answers.
DEBUG ============== user ==============
DEBUG calculate the sum of 2 and 4
▰▱▱▱▱▱▱ Thinking…
┏━ Message ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ┃
┃ calculate the sum of 2 and 4 ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Traceback (most recent call last):
File “C:\learn\HuggingFace\OCI_IAM_AI_LLAMA.py”, line 41, in
agent.print_response(“calculate the sum of 2 and 4”,stream=True)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\phi\agent\agent.py”, line 2783, in print_response
for resp in self.run(message=message, messages=messages, stream=True, **kwargs):
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\phi\agent\agent.py”, line 1794, in _run
for model_response_chunk in self.model.response_stream(messages=messages_for_model):
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\phi\model\huggingface\hf.py”, line 736, in response_stream
_tool_calls = self._build_tool_calls(stream_data.response_tool_calls)
File “C:\Users\Admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\phi\model\huggingface\hf.py”, line 826, in _build_tool_calls
_tool_call_id = _tool_call.id
^^^^^^^^^^^^^
AttributeError: ‘str’ object has no attribute ‘id’

Hi @anshul.mittal
Thank you for reaching out and using Phidata! I’ve tagged the relevant engineers to assist you with your query. We aim to respond within 24 hours.
If this is urgent, please feel free to let us know, and we’ll do our best to prioritize it.
Thanks for your patience!

Hey @anshul.mittal, can you please share your code so I can help you better with debugging?

Hi @manthanguptaa ,

Code:

from phi.agent import Agent, RunResponse
from phi.model.huggingface import HuggingFaceChat
import oci

def sum(a: int, b: int) → str:
“Sum of a and b”
return str(a+b)

#meta-llama/Meta-Llama-3-8B-Instruct,mistralai/Mixtral-8x7B-Instruct-v0.1, microsoft/Phi-3.5-mini-instruct

agent = Agent(
model=HuggingFaceChat(
id=“meta-llama/Meta-Llama-3-8B-Instruct”,
#max_tokens=1024,
api_key=‘***’
),
tools=[sum],
show_tool_calls= True,
markdown=True,
debug_mode=True,
reasoning=True,
)

Print the response on the terminal

agent.print_response(“calculate the sum of 2 and 4”,stream=True)

So to create your own custom tools you have to follow this doc

Your correct implementation won’t work with it

I followed the document, still the same issue. my code is now as below:

from phi.agent import Agent, RunResponse
from phi.model.huggingface import HuggingFaceChat
from phi.tools import Toolkit
import oci

class IamTools(Toolkit):

def __init__(self):
    super().__init__(name="IamTools")
    #self.register(self.get_User_Details)
    self.register(self.sum)

# def get_User_Details() -> str: 
#     config = oci.config.from_file ("C:\\oci\\config", "DEFAULT")
#     identity = oci.identity.IdentityClient(config) 
#     user = identity.get_user(config["user"]).data    
#     return str(user)

def sum(a: int, b: int) -> str:
    "Sum of a and b"
    return str(a+b)

#meta-llama/Meta-Llama-3-8B-Instruct,mistralai/Mixtral-8x7B-Instruct-v0.1, microsoft/Phi-3.5-mini-instruct

agent = Agent(
model=HuggingFaceChat(
id=“meta-llama/Meta-Llama-3-8B-Instruct”,
max_tokens=1024,
api_key=‘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’
),
tools=[IamTools()],
show_tool_calls= True,
markdown=True,
debug_mode=True,
reasoning=True,
instructions=[“output in table form”]
)

Print the response on the terminal

agent.print_response(“how to find permission inherited from other compartments in OCI IAM for particular user, provide the programming syntax in python and execute the code”)
agent.print_response(“calculate the sum of 2 and 4”,stream=True)
agent.print_response(“get user details”,stream=True)

@anshul.mittal there is some issue with HuggingFaceChat class on our end and we are on it to fix it. Follow this github issue Error when using Hugginface Inference API with Phidata tools · Issue #1618 · phidatahq/phidata · GitHub

Thanks @manthanguptaa for an update.