Closed tanaygodse closed 1 month ago
Thank you for raising this issue.
The docs need to be updated as we are currently in the migration phase from pydantic V1 to V2 which means that the pydantic Field
is currently incompatible.
To fix this please remove the from pydantic import Field
import and instead import the Field
from uagents directly:
from uagents import Agent, Context, Protocol, Model, Field # Field needs to be added here
Moving this issue now to docs
Prerequisites
Category
Bug (unexpected behavior)
Expected Behavior
Should be able to set up agent functions by following examples in docs
Observed Behavior
Title: Agent Functions showing "TypeError: Object of type 'FieldInfo' is not JSON serializable" Docs Link: https://fetch.ai/docs/guides/agents/intermediate/agent-functions Issue: Getting: "TypeError: Object of type 'FieldInfo' is not JSON serializable" on Line: "@dice_roll_protocol.on_message(model=Request, replies={UAgentResponse})"
Code: from uagents.setup import fund_agent_if_low from uagents import Agent, Context, Protocol, Model import random from pydantic import Field from ai_engine import UAgentResponse, UAgentResponseType import sys
dungeons = Agent( name="dungeonsanddragonsdiceroll", port=6145, seed="RANDOM STRINGS dnd", endpoint=["http://localhost:6145/submit"], )
print(f"Agent address is {dungeons.address}")
fund_agent_if_low(dungeons.wallet.address())
@dungeons.on_event("startup") async def hi(ctx: Context): ctx.logger.info(dungeons.address)
class Request(Model): dice_sides: int = Field(description="How many sides does your dice need?")
dice_roll_protocol = Protocol("DungeonsAndDragonsDiceRoll")
@dice_roll_protocol.on_message(model=Request, replies={UAgentResponse}) async def roll_dice(ctx: Context, sender: str, msg: Request): result = str(random.randint(1, msg.dice_sides)) message = f"Dice roll result: {result}" await ctx.send( sender, UAgentResponse(message=message, type=UAgentResponseType.FINAL) )
dungeons.include(dice_roll_protocol, publish_manifest=True)
dungeons.run()
Similar issue on pydantic github: https://github.com/pydantic/pydantic/issues/3388
To Reproduce
No response
Version
v.0.15.2
Environment Details (Optional)
No response
Failure Logs (Optional)
No response
Additional Information (Optional)
No response