mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Fixed foundry sample issue (#403)
Co-authored-by: Giles Odigwe <gilesodigwe@microsoft.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
53866218d2
commit
80b0920e58
@@ -24,26 +24,27 @@ async def main() -> None:
|
||||
print("=== Foundry Chat Client with Existing Agent ===")
|
||||
|
||||
# Create the client
|
||||
client = AIProjectClient(endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=AzureCliCredential())
|
||||
async with AIProjectClient(
|
||||
endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=AzureCliCredential()
|
||||
) as client:
|
||||
# Create an agent that will persist
|
||||
created_agent = await client.agents.create_agent(
|
||||
model=os.environ["FOUNDRY_MODEL_DEPLOYMENT_NAME"], name="WeatherAgent"
|
||||
)
|
||||
|
||||
# Create an agent that will persist
|
||||
created_agent = await client.agents.create_agent(
|
||||
model=os.environ["FOUNDRY_MODEL_DEPLOYMENT_NAME"], name="WeatherAgent"
|
||||
)
|
||||
|
||||
try:
|
||||
async with ChatClientAgent(
|
||||
# passing in the client is optional here, so if you take the agent_id from the portal
|
||||
# you can use it directly without the two lines above.
|
||||
chat_client=FoundryChatClient(client=client, agent_id=created_agent.id),
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
) as agent:
|
||||
result = await agent.run("What's the weather like in Tokyo?")
|
||||
print(f"Result: {result}\n")
|
||||
finally:
|
||||
# Clean up the agent manually
|
||||
await client.agents.delete_agent(created_agent.id)
|
||||
try:
|
||||
async with ChatClientAgent(
|
||||
# passing in the client is optional here, so if you take the agent_id from the portal
|
||||
# you can use it directly without the two lines above.
|
||||
chat_client=FoundryChatClient(client=client, agent_id=created_agent.id),
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
) as agent:
|
||||
result = await agent.run("What's the weather like in Tokyo?")
|
||||
print(f"Result: {result}\n")
|
||||
finally:
|
||||
# Clean up the agent manually
|
||||
await client.agents.delete_agent(created_agent.id)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user