from agents.extensions.models.litellm_model import LitellmModel
from agents import set_tracing_disabled
from openai import AsyncOpenAI
import os
from dotenv import load_dotenv
load_dotenv()
chat_model = "deepseek/deepseek-chat"
client = AsyncOpenAI(
api_key=os.getenv("DEEPSEEK_API_KEY"),
base_url = "https://api.deepseek.com",
)
set_tracing_disabled(disabled=True)
llm = LitellmModel(model=chat_model, api_key = os.getenv("DEEPSEEK_API_KEY"), base_url = "https://api.deepseek.com")
from agents import Agent
coder_agent = Agent(
name = "Coder",
handoff_description = "an expert coder that can write code in any language.",
instructions = "You are an expert coder. You can write code in any language.",
model = llm,
)
doctor_agent = Agent(
name = "Doctor",
handoff_description = "an expert doctor that can answer any medical question.",
instructions = "You are an expert doctor. Return a prescription for the patient. If the question is not related to medicine, say 'I don't know, try other agents.'",
model = llm,
)
async def check_coder_or_doctor(ctx, agent, input_data):
res = GuardrailFunctionOutput(output_info=None, tripwire_triggered=True)
if "code" in input_data or "coding" in input_data or "program" in input_data:
res.tripwire_triggered = False
if "medical" in input_data or "medicine" in input_data or "health" in input_data or "cold" in input_data:
res.tripwire_triggered = False
return res
from agents import GuardrailFunctionOutput, InputGuardrail
triage_agent = Agent(
name = "Triage agent",
handoff_description = "an expert triage agent that can handoff to the appropriate agent based on the language of the request.",
instructions = "Handoff to the appropriate agent based on the language of the request.",
handoffs = [coder_agent, doctor_agent],
input_guardrails=[
InputGuardrail(guardrail_function=check_coder_or_doctor),
],
model = llm,
)
from agents import Runner
import asyncio
async def main():
result = await Runner.run(triage_agent, "how to treat a cold?")
print(result)
asyncio.run(main())
评论