mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [BREAKING] Renamed create_agent to as_agent (#3249)
* Renamed create_agent to as_agent * Override for as_agent * Added override
This commit is contained in:
committed by
GitHub
Unverified
parent
a151f10cc2
commit
5687e13221
@@ -28,14 +28,14 @@ async def main():
|
||||
"""Build and run a simple two node agent workflow: Writer then Reviewer."""
|
||||
# Create the Azure chat client. AzureCliCredential uses your current az login.
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
writer_agent = chat_client.create_agent(
|
||||
writer_agent = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You are an excellent content writer. You create new content and edit contents based on the feedback."
|
||||
),
|
||||
name="writer",
|
||||
)
|
||||
|
||||
reviewer_agent = chat_client.create_agent(
|
||||
reviewer_agent = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You are an excellent content reviewer."
|
||||
"Provide actionable feedback to the writer about the provided content."
|
||||
|
||||
@@ -52,7 +52,7 @@ class Writer(Executor):
|
||||
|
||||
def __init__(self, chat_client: AzureOpenAIChatClient, id: str = "writer"):
|
||||
# Create a domain specific agent using your configured AzureOpenAIChatClient.
|
||||
self.agent = chat_client.create_agent(
|
||||
self.agent = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You are an excellent content writer. You create new content and edit contents based on the feedback."
|
||||
),
|
||||
@@ -89,7 +89,7 @@ class Reviewer(Executor):
|
||||
|
||||
def __init__(self, chat_client: AzureOpenAIChatClient, id: str = "reviewer"):
|
||||
# Create a domain specific agent that evaluates and refines content.
|
||||
self.agent = chat_client.create_agent(
|
||||
self.agent = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You are an excellent content reviewer. You review the content and provide feedback to the writer."
|
||||
),
|
||||
|
||||
@@ -59,7 +59,7 @@ async def reverse_text(text: str, ctx: WorkflowContext[str]) -> None:
|
||||
|
||||
def create_agent() -> ChatAgent:
|
||||
"""Factory function to create a Writer agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=("You decode messages. Try to reconstruct the original message."),
|
||||
name="decoder",
|
||||
)
|
||||
|
||||
@@ -27,7 +27,7 @@ Prerequisites:
|
||||
|
||||
|
||||
def create_writer_agent(client: AzureAIAgentClient) -> ChatAgent:
|
||||
return client.create_agent(
|
||||
return client.as_agent(
|
||||
name="Writer",
|
||||
instructions=(
|
||||
"You are an excellent content writer. You create new content and edit contents based on the feedback."
|
||||
@@ -36,7 +36,7 @@ def create_writer_agent(client: AzureAIAgentClient) -> ChatAgent:
|
||||
|
||||
|
||||
def create_reviewer_agent(client: AzureAIAgentClient) -> ChatAgent:
|
||||
return client.create_agent(
|
||||
return client.as_agent(
|
||||
name="Reviewer",
|
||||
instructions=(
|
||||
"You are an excellent content reviewer. "
|
||||
|
||||
+2
-2
@@ -87,7 +87,7 @@ async def enrich_with_references(
|
||||
|
||||
|
||||
def create_research_agent():
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
name="research_agent",
|
||||
instructions=(
|
||||
"Produce a short, bullet-style briefing with two actionable ideas. Label the section as 'Initial Draft'."
|
||||
@@ -96,7 +96,7 @@ def create_research_agent():
|
||||
|
||||
|
||||
def create_final_editor_agent():
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
name="final_editor_agent",
|
||||
instructions=(
|
||||
"Use all conversation context (including external notes) to produce the final answer. "
|
||||
|
||||
@@ -27,7 +27,7 @@ Prerequisites:
|
||||
|
||||
|
||||
def create_writer_agent():
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You are an excellent content writer. You create new content and edit contents based on the feedback."
|
||||
),
|
||||
@@ -36,7 +36,7 @@ def create_writer_agent():
|
||||
|
||||
|
||||
def create_reviewer_agent():
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You are an excellent content reviewer."
|
||||
"Provide actionable feedback to the writer about the provided content."
|
||||
|
||||
+2
-2
@@ -168,7 +168,7 @@ class Coordinator(Executor):
|
||||
|
||||
def create_writer_agent() -> ChatAgent:
|
||||
"""Creates a writer agent with tools."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
name="writer_agent",
|
||||
instructions=(
|
||||
"You are a marketing writer. Call the available tools before drafting copy so you are precise. "
|
||||
@@ -182,7 +182,7 @@ def create_writer_agent() -> ChatAgent:
|
||||
|
||||
def create_final_editor_agent() -> ChatAgent:
|
||||
"""Creates a final editor agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
name="final_editor_agent",
|
||||
instructions=(
|
||||
"You are an editor who polishes marketing copy after human approval. "
|
||||
|
||||
@@ -28,7 +28,7 @@ async def main() -> None:
|
||||
# 1) Create three domain agents using AzureOpenAIChatClient
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
researcher = chat_client.create_agent(
|
||||
researcher = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You're an expert market and product researcher. Given a prompt, provide concise, factual insights,"
|
||||
" opportunities, and risks."
|
||||
@@ -36,7 +36,7 @@ async def main() -> None:
|
||||
name="researcher",
|
||||
)
|
||||
|
||||
marketer = chat_client.create_agent(
|
||||
marketer = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You're a creative marketing strategist. Craft compelling value propositions and target messaging"
|
||||
" aligned to the prompt."
|
||||
@@ -44,7 +44,7 @@ async def main() -> None:
|
||||
name="marketer",
|
||||
)
|
||||
|
||||
legal = chat_client.create_agent(
|
||||
legal = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You're a cautious legal/compliance reviewer. Highlight constraints, disclaimers, and policy concerns"
|
||||
" based on the prompt."
|
||||
|
||||
@@ -43,7 +43,7 @@ class Writer(Executor):
|
||||
|
||||
def __init__(self, id: str = "writer"):
|
||||
# Create a domain specific agent using your configured AzureOpenAIChatClient.
|
||||
self.agent = AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
self.agent = AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You are an excellent content writer. You create new content and edit contents based on the feedback."
|
||||
),
|
||||
@@ -85,7 +85,7 @@ class Reviewer(Executor):
|
||||
|
||||
def __init__(self, id: str = "reviewer"):
|
||||
# Create a domain specific agent that evaluates and refines content.
|
||||
self.agent = AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
self.agent = AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You are an excellent content reviewer. You review the content and provide feedback to the writer."
|
||||
),
|
||||
|
||||
@@ -35,7 +35,7 @@ async def main() -> None:
|
||||
workflow = (
|
||||
GroupChatBuilder()
|
||||
.with_agent_orchestrator(
|
||||
OpenAIChatClient().create_agent(
|
||||
OpenAIChatClient().as_agent(
|
||||
name="Orchestrator",
|
||||
instructions="You coordinate a team conversation to solve the user's task.",
|
||||
)
|
||||
|
||||
@@ -66,7 +66,7 @@ def create_agents(chat_client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAg
|
||||
Tuple of (triage_agent, refund_agent, order_agent, return_agent)
|
||||
"""
|
||||
# Triage agent: Acts as the frontline dispatcher
|
||||
triage_agent = chat_client.create_agent(
|
||||
triage_agent = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You are frontline support triage. Route customer issues to the appropriate specialist agents "
|
||||
"based on the problem described."
|
||||
@@ -75,7 +75,7 @@ def create_agents(chat_client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAg
|
||||
)
|
||||
|
||||
# Refund specialist: Handles refund requests
|
||||
refund_agent = chat_client.create_agent(
|
||||
refund_agent = chat_client.as_agent(
|
||||
instructions="You process refund requests.",
|
||||
name="refund_agent",
|
||||
# In a real application, an agent can have multiple tools; here we keep it simple
|
||||
@@ -83,7 +83,7 @@ def create_agents(chat_client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAg
|
||||
)
|
||||
|
||||
# Order/shipping specialist: Resolves delivery issues
|
||||
order_agent = chat_client.create_agent(
|
||||
order_agent = chat_client.as_agent(
|
||||
instructions="You handle order and shipping inquiries.",
|
||||
name="order_agent",
|
||||
# In a real application, an agent can have multiple tools; here we keep it simple
|
||||
@@ -91,7 +91,7 @@ def create_agents(chat_client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAg
|
||||
)
|
||||
|
||||
# Return specialist: Handles return requests
|
||||
return_agent = chat_client.create_agent(
|
||||
return_agent = chat_client.as_agent(
|
||||
instructions="You manage product return requests.",
|
||||
name="return_agent",
|
||||
# In a real application, an agent can have multiple tools; here we keep it simple
|
||||
|
||||
@@ -82,7 +82,7 @@ def create_coding_agent(client: AzureAIAgentClient) -> ChatAgent:
|
||||
Returns:
|
||||
A ChatAgent configured with coding instructions and tools
|
||||
"""
|
||||
return client.create_agent(
|
||||
return client.as_agent(
|
||||
name="CodingAgent",
|
||||
instructions=("You are a helpful assistant that can write and execute Python code to solve problems."),
|
||||
tools=HostedCodeInterpreterTool(),
|
||||
|
||||
@@ -29,12 +29,12 @@ async def main() -> None:
|
||||
# 1) Create agents
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
writer = chat_client.create_agent(
|
||||
writer = chat_client.as_agent(
|
||||
instructions=("You are a concise copywriter. Provide a single, punchy marketing sentence based on the prompt."),
|
||||
name="writer",
|
||||
)
|
||||
|
||||
reviewer = chat_client.create_agent(
|
||||
reviewer = chat_client.as_agent(
|
||||
instructions=("You are a thoughtful reviewer. Give brief feedback on the previous assistant message."),
|
||||
name="reviewer",
|
||||
)
|
||||
|
||||
@@ -79,7 +79,7 @@ async def main() -> None:
|
||||
chat_client = OpenAIChatClient()
|
||||
|
||||
# Create agent with tools that use kwargs
|
||||
agent = chat_client.create_agent(
|
||||
agent = chat_client.as_agent(
|
||||
name="assistant",
|
||||
instructions=(
|
||||
"You are a helpful assistant. Use the available tools to help users. "
|
||||
|
||||
@@ -40,7 +40,7 @@ async def main() -> None:
|
||||
|
||||
# Define factory functions for workflow participants
|
||||
def create_assistant() -> ChatAgent:
|
||||
return chat_client.create_agent(
|
||||
return chat_client.as_agent(
|
||||
name="assistant",
|
||||
instructions=(
|
||||
"You are a helpful assistant. Answer questions based on the conversation "
|
||||
@@ -49,7 +49,7 @@ async def main() -> None:
|
||||
)
|
||||
|
||||
def create_summarizer() -> ChatAgent:
|
||||
return chat_client.create_agent(
|
||||
return chat_client.as_agent(
|
||||
name="summarizer",
|
||||
instructions=(
|
||||
"You are a summarizer. After the assistant responds, provide a brief "
|
||||
@@ -124,7 +124,7 @@ async def demonstrate_thread_serialization() -> None:
|
||||
chat_client = OpenAIChatClient()
|
||||
|
||||
def create_assistant() -> ChatAgent:
|
||||
return chat_client.create_agent(
|
||||
return chat_client.as_agent(
|
||||
name="memory_assistant",
|
||||
instructions="You are a helpful assistant with good memory. Remember details from our conversation.",
|
||||
)
|
||||
|
||||
+1
-1
@@ -178,7 +178,7 @@ def create_workflow(checkpoint_storage: FileCheckpointStorage) -> Workflow:
|
||||
workflow_builder = (
|
||||
WorkflowBuilder(max_iterations=6)
|
||||
.register_agent(
|
||||
lambda: AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
lambda: AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions="Write concise, warm release notes that sound human and helpful.",
|
||||
# The agent name is stable across runs which keeps checkpoints deterministic.
|
||||
name="writer",
|
||||
|
||||
+3
-3
@@ -60,7 +60,7 @@ def submit_refund(refund_description: str, amount: str, order_id: str) -> str:
|
||||
def create_agents(client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAgent, ChatAgent]:
|
||||
"""Create a simple handoff scenario: triage, refund, and order specialists."""
|
||||
|
||||
triage = client.create_agent(
|
||||
triage = client.as_agent(
|
||||
name="triage_agent",
|
||||
instructions=(
|
||||
"You are a customer service triage agent. Listen to customer issues and determine "
|
||||
@@ -69,7 +69,7 @@ def create_agents(client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAgent,
|
||||
),
|
||||
)
|
||||
|
||||
refund = client.create_agent(
|
||||
refund = client.as_agent(
|
||||
name="refund_agent",
|
||||
instructions=(
|
||||
"You are a refund specialist. Help customers with refund requests. "
|
||||
@@ -80,7 +80,7 @@ def create_agents(client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAgent,
|
||||
tools=[submit_refund],
|
||||
)
|
||||
|
||||
order = client.create_agent(
|
||||
order = client.as_agent(
|
||||
name="order_agent",
|
||||
instructions=(
|
||||
"You are an order tracking specialist. Help customers track their orders. "
|
||||
|
||||
@@ -44,13 +44,13 @@ async def basic_checkpointing() -> None:
|
||||
chat_client = OpenAIChatClient()
|
||||
|
||||
def create_assistant() -> ChatAgent:
|
||||
return chat_client.create_agent(
|
||||
return chat_client.as_agent(
|
||||
name="assistant",
|
||||
instructions="You are a helpful assistant. Keep responses brief.",
|
||||
)
|
||||
|
||||
def create_reviewer() -> ChatAgent:
|
||||
return chat_client.create_agent(
|
||||
return chat_client.as_agent(
|
||||
name="reviewer",
|
||||
instructions="You are a reviewer. Provide a one-sentence summary of the assistant's response.",
|
||||
)
|
||||
@@ -88,7 +88,7 @@ async def checkpointing_with_thread() -> None:
|
||||
chat_client = OpenAIChatClient()
|
||||
|
||||
def create_assistant() -> ChatAgent:
|
||||
return chat_client.create_agent(
|
||||
return chat_client.as_agent(
|
||||
name="memory_assistant",
|
||||
instructions="You are a helpful assistant with good memory. Reference previous conversation when relevant.",
|
||||
)
|
||||
@@ -132,7 +132,7 @@ async def streaming_with_checkpoints() -> None:
|
||||
chat_client = OpenAIChatClient()
|
||||
|
||||
def create_assistant() -> ChatAgent:
|
||||
return chat_client.create_agent(
|
||||
return chat_client.as_agent(
|
||||
name="streaming_assistant",
|
||||
instructions="You are a helpful assistant.",
|
||||
)
|
||||
|
||||
@@ -75,7 +75,7 @@ async def main() -> None:
|
||||
chat_client = OpenAIChatClient()
|
||||
|
||||
# Create an agent with tools that use kwargs
|
||||
inner_agent = chat_client.create_agent(
|
||||
inner_agent = chat_client.as_agent(
|
||||
name="data_agent",
|
||||
instructions=(
|
||||
"You are a data access agent. Use the available tools to help users. "
|
||||
|
||||
@@ -131,7 +131,7 @@ async def to_email_assistant_request(
|
||||
def create_spam_detector_agent() -> ChatAgent:
|
||||
"""Helper to create a spam detection agent."""
|
||||
# AzureCliCredential uses your current az login. This avoids embedding secrets in code.
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You are a spam detection assistant that identifies spam emails. "
|
||||
"Always return JSON with fields is_spam (bool), reason (string), and email_content (string). "
|
||||
@@ -145,7 +145,7 @@ def create_spam_detector_agent() -> ChatAgent:
|
||||
def create_email_assistant_agent() -> ChatAgent:
|
||||
"""Helper to create an email assistant agent."""
|
||||
# AzureCliCredential uses your current az login. This avoids embedding secrets in code.
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You are an email assistant that helps users draft professional responses to emails. "
|
||||
"Your input may be a JSON object that includes 'email_content'; base your reply on that content. "
|
||||
|
||||
@@ -183,7 +183,7 @@ async def database_access(analysis: AnalysisResult, ctx: WorkflowContext[Never,
|
||||
|
||||
def create_email_analysis_agent() -> ChatAgent:
|
||||
"""Creates the email analysis agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You are a spam detection assistant that identifies spam emails. "
|
||||
"Always return JSON with fields 'spam_decision' (one of NotSpam, Spam, Uncertain) "
|
||||
@@ -196,7 +196,7 @@ def create_email_analysis_agent() -> ChatAgent:
|
||||
|
||||
def create_email_assistant_agent() -> ChatAgent:
|
||||
"""Creates the email assistant agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=("You are an email assistant that helps users draft responses to emails with professionalism."),
|
||||
name="email_assistant_agent",
|
||||
default_options={"response_format": EmailResponse},
|
||||
@@ -205,7 +205,7 @@ def create_email_assistant_agent() -> ChatAgent:
|
||||
|
||||
def create_email_summary_agent() -> ChatAgent:
|
||||
"""Creates the email summary agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=("You are an assistant that helps users summarize emails."),
|
||||
name="email_summary_agent",
|
||||
default_options={"response_format": EmailSummaryModel},
|
||||
|
||||
@@ -117,7 +117,7 @@ class ParseJudgeResponse(Executor):
|
||||
|
||||
def create_judge_agent() -> ChatAgent:
|
||||
"""Create a judge agent that evaluates guesses."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=("You strictly respond with one of: MATCHED, ABOVE, BELOW based on the given target and guess."),
|
||||
name="judge_agent",
|
||||
)
|
||||
|
||||
@@ -154,7 +154,7 @@ async def handle_uncertain(detection: DetectionResult, ctx: WorkflowContext[Neve
|
||||
|
||||
def create_spam_detection_agent() -> ChatAgent:
|
||||
"""Create and return the spam detection agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You are a spam detection assistant that identifies spam emails. "
|
||||
"Be less confident in your assessments. "
|
||||
@@ -168,7 +168,7 @@ def create_spam_detection_agent() -> ChatAgent:
|
||||
|
||||
def create_email_assistant_agent() -> ChatAgent:
|
||||
"""Create and return the email assistant agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=("You are an email assistant that helps users draft responses to emails with professionalism."),
|
||||
name="email_assistant_agent",
|
||||
default_options={"response_format": EmailResponse},
|
||||
|
||||
@@ -168,40 +168,40 @@ async def main() -> None:
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
# Create agents with structured outputs
|
||||
self_service_agent = chat_client.create_agent(
|
||||
self_service_agent = chat_client.as_agent(
|
||||
name="SelfServiceAgent",
|
||||
instructions=SELF_SERVICE_INSTRUCTIONS,
|
||||
default_options={"response_format": SelfServiceResponse},
|
||||
)
|
||||
|
||||
ticketing_agent = chat_client.create_agent(
|
||||
ticketing_agent = chat_client.as_agent(
|
||||
name="TicketingAgent",
|
||||
instructions=TICKETING_INSTRUCTIONS,
|
||||
tools=plugin.get_functions(),
|
||||
default_options={"response_format": TicketingResponse},
|
||||
)
|
||||
|
||||
routing_agent = chat_client.create_agent(
|
||||
routing_agent = chat_client.as_agent(
|
||||
name="TicketRoutingAgent",
|
||||
instructions=TICKET_ROUTING_INSTRUCTIONS,
|
||||
tools=[plugin.get_ticket],
|
||||
default_options={"response_format": RoutingResponse},
|
||||
)
|
||||
|
||||
windows_support_agent = chat_client.create_agent(
|
||||
windows_support_agent = chat_client.as_agent(
|
||||
name="WindowsSupportAgent",
|
||||
instructions=WINDOWS_SUPPORT_INSTRUCTIONS,
|
||||
tools=[plugin.get_ticket],
|
||||
default_options={"response_format": SupportResponse},
|
||||
)
|
||||
|
||||
resolution_agent = chat_client.create_agent(
|
||||
resolution_agent = chat_client.as_agent(
|
||||
name="TicketResolutionAgent",
|
||||
instructions=RESOLUTION_INSTRUCTIONS,
|
||||
tools=[plugin.resolve_ticket],
|
||||
)
|
||||
|
||||
escalation_agent = chat_client.create_agent(
|
||||
escalation_agent = chat_client.as_agent(
|
||||
name="TicketEscalationAgent",
|
||||
instructions=ESCALATION_INSTRUCTIONS,
|
||||
tools=[plugin.get_ticket, plugin.send_notification],
|
||||
|
||||
@@ -126,38 +126,38 @@ async def main() -> None:
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
# Create agents
|
||||
research_agent = chat_client.create_agent(
|
||||
research_agent = chat_client.as_agent(
|
||||
name="ResearchAgent",
|
||||
instructions=RESEARCH_INSTRUCTIONS,
|
||||
)
|
||||
|
||||
planner_agent = chat_client.create_agent(
|
||||
planner_agent = chat_client.as_agent(
|
||||
name="PlannerAgent",
|
||||
instructions=PLANNER_INSTRUCTIONS,
|
||||
)
|
||||
|
||||
manager_agent = chat_client.create_agent(
|
||||
manager_agent = chat_client.as_agent(
|
||||
name="ManagerAgent",
|
||||
instructions=MANAGER_INSTRUCTIONS,
|
||||
default_options={"response_format": ManagerResponse},
|
||||
)
|
||||
|
||||
summary_agent = chat_client.create_agent(
|
||||
summary_agent = chat_client.as_agent(
|
||||
name="SummaryAgent",
|
||||
instructions=SUMMARY_INSTRUCTIONS,
|
||||
)
|
||||
|
||||
knowledge_agent = chat_client.create_agent(
|
||||
knowledge_agent = chat_client.as_agent(
|
||||
name="KnowledgeAgent",
|
||||
instructions=KNOWLEDGE_INSTRUCTIONS,
|
||||
)
|
||||
|
||||
coder_agent = chat_client.create_agent(
|
||||
coder_agent = chat_client.as_agent(
|
||||
name="CoderAgent",
|
||||
instructions=CODER_INSTRUCTIONS,
|
||||
)
|
||||
|
||||
weather_agent = chat_client.create_agent(
|
||||
weather_agent = chat_client.as_agent(
|
||||
name="WeatherAgent",
|
||||
instructions=WEATHER_INSTRUCTIONS,
|
||||
)
|
||||
|
||||
@@ -73,7 +73,7 @@ Session Complete
|
||||
```python
|
||||
# Create the agent with tools
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
menu_agent = chat_client.create_agent(
|
||||
menu_agent = chat_client.as_agent(
|
||||
name="MenuAgent",
|
||||
instructions="You are a helpful restaurant menu assistant...",
|
||||
tools=[get_menu, get_specials, get_item_price],
|
||||
|
||||
@@ -59,7 +59,7 @@ def get_item_price(name: Annotated[str, Field(description="Menu item name")]) ->
|
||||
async def main():
|
||||
# Create agent with tools
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
menu_agent = chat_client.create_agent(
|
||||
menu_agent = chat_client.as_agent(
|
||||
name="MenuAgent",
|
||||
instructions="Answer questions about menu items, specials, and prices.",
|
||||
tools=[get_menu, get_specials, get_item_price],
|
||||
|
||||
@@ -52,15 +52,15 @@ async def main() -> None:
|
||||
"""Run the marketing workflow with real Azure AI agents."""
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
analyst_agent = chat_client.create_agent(
|
||||
analyst_agent = chat_client.as_agent(
|
||||
name="AnalystAgent",
|
||||
instructions=ANALYST_INSTRUCTIONS,
|
||||
)
|
||||
writer_agent = chat_client.create_agent(
|
||||
writer_agent = chat_client.as_agent(
|
||||
name="WriterAgent",
|
||||
instructions=WRITER_INSTRUCTIONS,
|
||||
)
|
||||
editor_agent = chat_client.create_agent(
|
||||
editor_agent = chat_client.as_agent(
|
||||
name="EditorAgent",
|
||||
instructions=EDITOR_INSTRUCTIONS,
|
||||
)
|
||||
|
||||
@@ -55,12 +55,12 @@ async def main() -> None:
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
# Create student and teacher agents
|
||||
student_agent = chat_client.create_agent(
|
||||
student_agent = chat_client.as_agent(
|
||||
name="StudentAgent",
|
||||
instructions=STUDENT_INSTRUCTIONS,
|
||||
)
|
||||
|
||||
teacher_agent = chat_client.create_agent(
|
||||
teacher_agent = chat_client.as_agent(
|
||||
name="TeacherAgent",
|
||||
instructions=TEACHER_INSTRUCTIONS,
|
||||
)
|
||||
|
||||
+1
-1
@@ -213,7 +213,7 @@ async def conclude_workflow(
|
||||
|
||||
def create_email_writer_agent() -> ChatAgent:
|
||||
"""Create the Email Writer agent with tools that require approval."""
|
||||
return OpenAIChatClient().create_agent(
|
||||
return OpenAIChatClient().as_agent(
|
||||
name="Email Writer",
|
||||
instructions=("You are an excellent email assistant. You respond to incoming emails."),
|
||||
# tools with `approval_mode="always_require"` will trigger approval requests
|
||||
|
||||
+3
-3
@@ -99,7 +99,7 @@ async def main() -> None:
|
||||
_chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
# Create agents that analyze from different perspectives
|
||||
technical_analyst = _chat_client.create_agent(
|
||||
technical_analyst = _chat_client.as_agent(
|
||||
name="technical_analyst",
|
||||
instructions=(
|
||||
"You are a technical analyst. When given a topic, provide a technical "
|
||||
@@ -108,7 +108,7 @@ async def main() -> None:
|
||||
),
|
||||
)
|
||||
|
||||
business_analyst = _chat_client.create_agent(
|
||||
business_analyst = _chat_client.as_agent(
|
||||
name="business_analyst",
|
||||
instructions=(
|
||||
"You are a business analyst. When given a topic, provide a business "
|
||||
@@ -117,7 +117,7 @@ async def main() -> None:
|
||||
),
|
||||
)
|
||||
|
||||
user_experience_analyst = _chat_client.create_agent(
|
||||
user_experience_analyst = _chat_client.as_agent(
|
||||
name="ux_analyst",
|
||||
instructions=(
|
||||
"You are a UX analyst. When given a topic, provide a user experience "
|
||||
|
||||
+4
-4
@@ -44,7 +44,7 @@ async def main() -> None:
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
# Create agents for a group discussion
|
||||
optimist = chat_client.create_agent(
|
||||
optimist = chat_client.as_agent(
|
||||
name="optimist",
|
||||
instructions=(
|
||||
"You are an optimistic team member. You see opportunities and potential "
|
||||
@@ -53,7 +53,7 @@ async def main() -> None:
|
||||
),
|
||||
)
|
||||
|
||||
pragmatist = chat_client.create_agent(
|
||||
pragmatist = chat_client.as_agent(
|
||||
name="pragmatist",
|
||||
instructions=(
|
||||
"You are a pragmatic team member. You focus on practical implementation "
|
||||
@@ -62,7 +62,7 @@ async def main() -> None:
|
||||
),
|
||||
)
|
||||
|
||||
creative = chat_client.create_agent(
|
||||
creative = chat_client.as_agent(
|
||||
name="creative",
|
||||
instructions=(
|
||||
"You are a creative team member. You propose innovative solutions and "
|
||||
@@ -72,7 +72,7 @@ async def main() -> None:
|
||||
)
|
||||
|
||||
# Orchestrator coordinates the discussion
|
||||
orchestrator = chat_client.create_agent(
|
||||
orchestrator = chat_client.as_agent(
|
||||
name="orchestrator",
|
||||
instructions=(
|
||||
"You are a discussion manager coordinating a team conversation between participants. "
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ class TurnManager(Executor):
|
||||
|
||||
def create_guessing_agent() -> ChatAgent:
|
||||
"""Create the guessing agent with instructions to guess a number between 1 and 10."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
name="GuessingAgent",
|
||||
instructions=(
|
||||
"You guess a number between 1 and 10. "
|
||||
|
||||
+3
-3
@@ -41,12 +41,12 @@ async def main() -> None:
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
# Create agents for a sequential document review workflow
|
||||
drafter = chat_client.create_agent(
|
||||
drafter = chat_client.as_agent(
|
||||
name="drafter",
|
||||
instructions=("You are a document drafter. When given a topic, create a brief draft (2-3 sentences)."),
|
||||
)
|
||||
|
||||
editor = chat_client.create_agent(
|
||||
editor = chat_client.as_agent(
|
||||
name="editor",
|
||||
instructions=(
|
||||
"You are an editor. Review the draft and make improvements. "
|
||||
@@ -54,7 +54,7 @@ async def main() -> None:
|
||||
),
|
||||
)
|
||||
|
||||
finalizer = chat_client.create_agent(
|
||||
finalizer = chat_client.as_agent(
|
||||
name="finalizer",
|
||||
instructions=(
|
||||
"You are a finalizer. Take the edited content and create a polished final version. "
|
||||
|
||||
@@ -30,7 +30,7 @@ async def main() -> None:
|
||||
# 1) Create three domain agents using AzureOpenAIChatClient
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
researcher = chat_client.create_agent(
|
||||
researcher = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You're an expert market and product researcher. Given a prompt, provide concise, factual insights,"
|
||||
" opportunities, and risks."
|
||||
@@ -38,7 +38,7 @@ async def main() -> None:
|
||||
name="researcher",
|
||||
)
|
||||
|
||||
marketer = chat_client.create_agent(
|
||||
marketer = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You're a creative marketing strategist. Craft compelling value propositions and target messaging"
|
||||
" aligned to the prompt."
|
||||
@@ -46,7 +46,7 @@ async def main() -> None:
|
||||
name="marketer",
|
||||
)
|
||||
|
||||
legal = chat_client.create_agent(
|
||||
legal = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You're a cautious legal/compliance reviewer. Highlight constraints, disclaimers, and policy concerns"
|
||||
" based on the prompt."
|
||||
|
||||
+3
-3
@@ -40,7 +40,7 @@ class ResearcherExec(Executor):
|
||||
agent: ChatAgent
|
||||
|
||||
def __init__(self, chat_client: AzureOpenAIChatClient, id: str = "researcher"):
|
||||
self.agent = chat_client.create_agent(
|
||||
self.agent = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You're an expert market and product researcher. Given a prompt, provide concise, factual insights,"
|
||||
" opportunities, and risks."
|
||||
@@ -60,7 +60,7 @@ class MarketerExec(Executor):
|
||||
agent: ChatAgent
|
||||
|
||||
def __init__(self, chat_client: AzureOpenAIChatClient, id: str = "marketer"):
|
||||
self.agent = chat_client.create_agent(
|
||||
self.agent = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You're a creative marketing strategist. Craft compelling value propositions and target messaging"
|
||||
" aligned to the prompt."
|
||||
@@ -80,7 +80,7 @@ class LegalExec(Executor):
|
||||
agent: ChatAgent
|
||||
|
||||
def __init__(self, chat_client: AzureOpenAIChatClient, id: str = "legal"):
|
||||
self.agent = chat_client.create_agent(
|
||||
self.agent = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You're a cautious legal/compliance reviewer. Highlight constraints, disclaimers, and policy concerns"
|
||||
" based on the prompt."
|
||||
|
||||
+3
-3
@@ -30,21 +30,21 @@ Prerequisites:
|
||||
async def main() -> None:
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
researcher = chat_client.create_agent(
|
||||
researcher = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You're an expert market and product researcher. Given a prompt, provide concise, factual insights,"
|
||||
" opportunities, and risks."
|
||||
),
|
||||
name="researcher",
|
||||
)
|
||||
marketer = chat_client.create_agent(
|
||||
marketer = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You're a creative marketing strategist. Craft compelling value propositions and target messaging"
|
||||
" aligned to the prompt."
|
||||
),
|
||||
name="marketer",
|
||||
)
|
||||
legal = chat_client.create_agent(
|
||||
legal = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You're a cautious legal/compliance reviewer. Highlight constraints, disclaimers, and policy concerns"
|
||||
" based on the prompt."
|
||||
|
||||
+3
-3
@@ -46,7 +46,7 @@ Prerequisites:
|
||||
|
||||
def create_researcher() -> ChatAgent:
|
||||
"""Factory function to create a researcher agent instance."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You're an expert market and product researcher. Given a prompt, provide concise, factual insights,"
|
||||
" opportunities, and risks."
|
||||
@@ -57,7 +57,7 @@ def create_researcher() -> ChatAgent:
|
||||
|
||||
def create_marketer() -> ChatAgent:
|
||||
"""Factory function to create a marketer agent instance."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You're a creative marketing strategist. Craft compelling value propositions and target messaging"
|
||||
" aligned to the prompt."
|
||||
@@ -68,7 +68,7 @@ def create_marketer() -> ChatAgent:
|
||||
|
||||
def create_legal() -> ChatAgent:
|
||||
"""Factory function to create a legal/compliance agent instance."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You're a cautious legal/compliance reviewer. Highlight constraints, disclaimers, and policy concerns"
|
||||
" based on the prompt."
|
||||
|
||||
@@ -44,7 +44,7 @@ def create_agents(
|
||||
chat_client: AzureOpenAIChatClient,
|
||||
) -> tuple[ChatAgent, ChatAgent, ChatAgent]:
|
||||
"""Create coordinator and specialists for autonomous iteration."""
|
||||
coordinator = chat_client.create_agent(
|
||||
coordinator = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You are a coordinator. You break down a user query into a research task and a summary task. "
|
||||
"Assign the two tasks to the appropriate specialists, one after the other."
|
||||
@@ -52,7 +52,7 @@ def create_agents(
|
||||
name="coordinator",
|
||||
)
|
||||
|
||||
research_agent = chat_client.create_agent(
|
||||
research_agent = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You are a research specialist that explores topics thoroughly using web search. "
|
||||
"When given a research task, break it down into multiple aspects and explore each one. "
|
||||
@@ -65,7 +65,7 @@ def create_agents(
|
||||
tools=[HostedWebSearchTool()],
|
||||
)
|
||||
|
||||
summary_agent = chat_client.create_agent(
|
||||
summary_agent = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You summarize research findings. Provide a concise, well-organized summary. When done, return "
|
||||
"control to the coordinator."
|
||||
|
||||
+4
-4
@@ -67,7 +67,7 @@ def process_return(order_number: Annotated[str, "Order number to process return
|
||||
|
||||
def create_triage_agent() -> ChatAgent:
|
||||
"""Factory function to create a triage agent instance."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You are frontline support triage. Route customer issues to the appropriate specialist agents "
|
||||
"based on the problem described."
|
||||
@@ -78,7 +78,7 @@ def create_triage_agent() -> ChatAgent:
|
||||
|
||||
def create_refund_agent() -> ChatAgent:
|
||||
"""Factory function to create a refund agent instance."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions="You process refund requests.",
|
||||
name="refund_agent",
|
||||
# In a real application, an agent can have multiple tools; here we keep it simple
|
||||
@@ -88,7 +88,7 @@ def create_refund_agent() -> ChatAgent:
|
||||
|
||||
def create_order_status_agent() -> ChatAgent:
|
||||
"""Factory function to create an order status agent instance."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions="You handle order and shipping inquiries.",
|
||||
name="order_agent",
|
||||
# In a real application, an agent can have multiple tools; here we keep it simple
|
||||
@@ -98,7 +98,7 @@ def create_order_status_agent() -> ChatAgent:
|
||||
|
||||
def create_return_agent() -> ChatAgent:
|
||||
"""Factory function to create a return agent instance."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions="You manage product return requests.",
|
||||
name="return_agent",
|
||||
# In a real application, an agent can have multiple tools; here we keep it simple
|
||||
|
||||
@@ -66,7 +66,7 @@ def create_agents(chat_client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAg
|
||||
Tuple of (triage_agent, refund_agent, order_agent, return_agent)
|
||||
"""
|
||||
# Triage agent: Acts as the frontline dispatcher
|
||||
triage_agent = chat_client.create_agent(
|
||||
triage_agent = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You are frontline support triage. Route customer issues to the appropriate specialist agents "
|
||||
"based on the problem described."
|
||||
@@ -75,7 +75,7 @@ def create_agents(chat_client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAg
|
||||
)
|
||||
|
||||
# Refund specialist: Handles refund requests
|
||||
refund_agent = chat_client.create_agent(
|
||||
refund_agent = chat_client.as_agent(
|
||||
instructions="You process refund requests.",
|
||||
name="refund_agent",
|
||||
# In a real application, an agent can have multiple tools; here we keep it simple
|
||||
@@ -83,7 +83,7 @@ def create_agents(chat_client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAg
|
||||
)
|
||||
|
||||
# Order/shipping specialist: Resolves delivery issues
|
||||
order_agent = chat_client.create_agent(
|
||||
order_agent = chat_client.as_agent(
|
||||
instructions="You handle order and shipping inquiries.",
|
||||
name="order_agent",
|
||||
# In a real application, an agent can have multiple tools; here we keep it simple
|
||||
@@ -91,7 +91,7 @@ def create_agents(chat_client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAg
|
||||
)
|
||||
|
||||
# Return specialist: Handles return requests
|
||||
return_agent = chat_client.create_agent(
|
||||
return_agent = chat_client.as_agent(
|
||||
instructions="You manage product return requests.",
|
||||
name="return_agent",
|
||||
# In a real application, an agent can have multiple tools; here we keep it simple
|
||||
|
||||
+4
-4
@@ -90,7 +90,7 @@ async def create_agents_v1(credential: AzureCliCredential) -> AsyncIterator[tupl
|
||||
from agent_framework.azure import AzureAIAgentClient
|
||||
|
||||
async with AzureAIAgentClient(credential=credential) as client:
|
||||
triage = client.create_agent(
|
||||
triage = client.as_agent(
|
||||
name="triage_agent",
|
||||
instructions=(
|
||||
"You are a triage agent. Route code-related requests to the code_specialist. "
|
||||
@@ -99,7 +99,7 @@ async def create_agents_v1(credential: AzureCliCredential) -> AsyncIterator[tupl
|
||||
),
|
||||
)
|
||||
|
||||
code_specialist = client.create_agent(
|
||||
code_specialist = client.as_agent(
|
||||
name="code_specialist",
|
||||
instructions=(
|
||||
"You are a Python code specialist. Use the code interpreter to execute Python code "
|
||||
@@ -124,12 +124,12 @@ async def create_agents_v2(credential: AzureCliCredential) -> AsyncIterator[tupl
|
||||
AzureAIClient(credential=credential) as triage_client,
|
||||
AzureAIClient(credential=credential) as code_client,
|
||||
):
|
||||
triage = triage_client.create_agent(
|
||||
triage = triage_client.as_agent(
|
||||
name="TriageAgent",
|
||||
instructions="You are a triage agent. Your ONLY job is to route requests to the appropriate specialist.",
|
||||
)
|
||||
|
||||
code_specialist = code_client.create_agent(
|
||||
code_specialist = code_client.as_agent(
|
||||
name="CodeSpecialist",
|
||||
instructions=(
|
||||
"You are a Python code specialist. You have access to a code interpreter tool. "
|
||||
|
||||
@@ -31,12 +31,12 @@ async def main() -> None:
|
||||
# 1) Create agents
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
writer = chat_client.create_agent(
|
||||
writer = chat_client.as_agent(
|
||||
instructions=("You are a concise copywriter. Provide a single, punchy marketing sentence based on the prompt."),
|
||||
name="writer",
|
||||
)
|
||||
|
||||
reviewer = chat_client.create_agent(
|
||||
reviewer = chat_client.as_agent(
|
||||
instructions=("You are a thoughtful reviewer. Give brief feedback on the previous assistant message."),
|
||||
name="reviewer",
|
||||
)
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ class Summarizer(Executor):
|
||||
async def main() -> None:
|
||||
# 1) Create a content agent
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
content = chat_client.create_agent(
|
||||
content = chat_client.as_agent(
|
||||
instructions="Produce a concise paragraph answering the user's request.",
|
||||
name="content",
|
||||
)
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ class Accumulate(Executor):
|
||||
|
||||
|
||||
def create_agent() -> ChatAgent:
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions="Produce a concise paragraph answering the user's request.",
|
||||
name="ContentProducer",
|
||||
)
|
||||
|
||||
@@ -94,7 +94,7 @@ class AggregateInsights(Executor):
|
||||
|
||||
def create_researcher_agent() -> ChatAgent:
|
||||
"""Creates a research domain expert agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You're an expert market and product researcher. Given a prompt, provide concise, factual insights,"
|
||||
" opportunities, and risks."
|
||||
@@ -105,7 +105,7 @@ def create_researcher_agent() -> ChatAgent:
|
||||
|
||||
def create_marketer_agent() -> ChatAgent:
|
||||
"""Creates a marketing domain expert agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You're a creative marketing strategist. Craft compelling value propositions and target messaging"
|
||||
" aligned to the prompt."
|
||||
@@ -116,7 +116,7 @@ def create_marketer_agent() -> ChatAgent:
|
||||
|
||||
def create_legal_agent() -> ChatAgent:
|
||||
"""Creates a legal/compliance domain expert agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You're a cautious legal/compliance reviewer. Highlight constraints, disclaimers, and policy concerns"
|
||||
" based on the prompt."
|
||||
|
||||
+2
-2
@@ -157,7 +157,7 @@ async def handle_spam(detection: DetectionResult, ctx: WorkflowContext[Never, st
|
||||
|
||||
def create_spam_detection_agent() -> ChatAgent:
|
||||
"""Creates a spam detection agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You are a spam detection assistant that identifies spam emails. "
|
||||
"Always return JSON with fields is_spam (bool) and reason (string)."
|
||||
@@ -170,7 +170,7 @@ def create_spam_detection_agent() -> ChatAgent:
|
||||
|
||||
def create_email_assistant_agent() -> ChatAgent:
|
||||
"""Creates an email assistant agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You are an email assistant that helps users draft responses to emails with professionalism. "
|
||||
"Return JSON with a single field 'response' containing the drafted reply."
|
||||
|
||||
@@ -73,7 +73,7 @@ async def main() -> None:
|
||||
chat_client = OpenAIChatClient()
|
||||
|
||||
# Create agent with tools that use kwargs
|
||||
agent = chat_client.create_agent(
|
||||
agent = chat_client.as_agent(
|
||||
name="assistant",
|
||||
instructions=(
|
||||
"You are a helpful assistant. Use the available tools to help users. "
|
||||
|
||||
+2
-2
@@ -104,7 +104,7 @@ async def main() -> None:
|
||||
# 3. Create two agents focused on different stocks but with the same tool sets
|
||||
chat_client = OpenAIChatClient()
|
||||
|
||||
microsoft_agent = chat_client.create_agent(
|
||||
microsoft_agent = chat_client.as_agent(
|
||||
name="MicrosoftAgent",
|
||||
instructions=(
|
||||
"You are a personal trading assistant focused on Microsoft (MSFT). "
|
||||
@@ -113,7 +113,7 @@ async def main() -> None:
|
||||
tools=[get_stock_price, get_market_sentiment, get_portfolio_balance, execute_trade],
|
||||
)
|
||||
|
||||
google_agent = chat_client.create_agent(
|
||||
google_agent = chat_client.as_agent(
|
||||
name="GoogleAgent",
|
||||
instructions=(
|
||||
"You are a personal trading assistant focused on Google (GOOGL). "
|
||||
|
||||
+2
-2
@@ -96,7 +96,7 @@ async def main() -> None:
|
||||
# 3. Create specialized agents
|
||||
chat_client = OpenAIChatClient()
|
||||
|
||||
qa_engineer = chat_client.create_agent(
|
||||
qa_engineer = chat_client.as_agent(
|
||||
name="QAEngineer",
|
||||
instructions=(
|
||||
"You are a QA engineer responsible for running tests before deployment. "
|
||||
@@ -105,7 +105,7 @@ async def main() -> None:
|
||||
tools=[run_tests],
|
||||
)
|
||||
|
||||
devops_engineer = chat_client.create_agent(
|
||||
devops_engineer = chat_client.as_agent(
|
||||
name="DevOpsEngineer",
|
||||
instructions=(
|
||||
"You are a DevOps engineer responsible for deployments. First check staging "
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ def get_database_schema() -> str:
|
||||
async def main() -> None:
|
||||
# 2. Create the agent with tools (approval mode is set per-tool via decorator)
|
||||
chat_client = OpenAIChatClient()
|
||||
database_agent = chat_client.create_agent(
|
||||
database_agent = chat_client.as_agent(
|
||||
name="DatabaseAgent",
|
||||
instructions=(
|
||||
"You are a database assistant. You can view the database schema and execute "
|
||||
|
||||
+3
-3
@@ -88,7 +88,7 @@ class AggregateInsights(Executor):
|
||||
|
||||
def create_researcher_agent() -> ChatAgent:
|
||||
"""Creates a research domain expert agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You're an expert market and product researcher. Given a prompt, provide concise, factual insights,"
|
||||
" opportunities, and risks."
|
||||
@@ -99,7 +99,7 @@ def create_researcher_agent() -> ChatAgent:
|
||||
|
||||
def create_marketer_agent() -> ChatAgent:
|
||||
"""Creates a marketing domain expert agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You're a creative marketing strategist. Craft compelling value propositions and target messaging"
|
||||
" aligned to the prompt."
|
||||
@@ -110,7 +110,7 @@ def create_marketer_agent() -> ChatAgent:
|
||||
|
||||
def create_legal_agent() -> ChatAgent:
|
||||
"""Creates a legal domain expert agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You're a cautious legal/compliance reviewer. Highlight constraints, disclaimers, and policy concerns"
|
||||
" based on the prompt."
|
||||
|
||||
Reference in New Issue
Block a user