fromdataclassesimportdataclassfrompydanticimportBaseModel,Fieldfrompydantic_aiimportAgent,RunContextclassDatabaseConn:"""This is a fake database for example purposes. In reality, you'd be connecting to an external database (e.g. PostgreSQL) to get information about customers. """@classmethodasyncdefcustomer_name(cls,*,id:int)->str|None:ifid==123:return'John'@classmethodasyncdefcustomer_balance(cls,*,id:int,include_pending:bool)->float:ifid==123andinclude_pending:return123.45else:raiseValueError('Customer not found')@dataclassclassSupportDependencies:customer_id:intdb:DatabaseConnclassSupportOutput(BaseModel):support_advice:str=Field(description='Advice returned to the customer')block_card:bool=Field(description='Whether to block their card or not')risk:int=Field(description='Risk level of query',ge=0,le=10)support_agent=Agent('openai:gpt-4o',deps_type=SupportDependencies,output_type=SupportOutput,system_prompt=('You are a support agent in our bank, give the ''customer support and judge the risk level of their query. '"Reply using the customer's name."),)@support_agent.system_promptasyncdefadd_customer_name(ctx:RunContext[SupportDependencies])->str:customer_name=awaitctx.deps.db.customer_name(id=ctx.deps.customer_id)returnf"The customer's name is {customer_name!r}"@support_agent.toolasyncdefcustomer_balance(ctx:RunContext[SupportDependencies],include_pending:bool)->str:"""Returns the customer's current account balance."""balance=awaitctx.deps.db.customer_balance(id=ctx.deps.customer_id,include_pending=include_pending,)returnf'${balance:.2f}'if__name__=='__main__':deps=SupportDependencies(customer_id=123,db=DatabaseConn())result=support_agent.run_sync('What is my balance?',deps=deps)print(result.output)""" support_advice='Hello John, your current account balance, including pending transactions, is $123.45.' block_card=False risk=1 """result=support_agent.run_sync('I just lost my card!',deps=deps)print(result.output)""" support_advice="I'm sorry to hear that, John. We are temporarily blocking your card to prevent unauthorized transactions." block_card=True risk=8 """