Azure / Azure/azure-sdk-for-python
Grounding with Bing search - Run failed: {'code': 'server_error', 'message': 'Sorry, something went wrong.'}
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 3.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 193
Description
Name: azure-ai-projects
Version: 1.0.0
- **Operating System: windows
- **Python Version**: Python 3.13.5
**Describe the bug**
i have created the agent with help of following steps:https://learn.microsoft.com/en-us/azure/ai-foundry/agents/how-to/tools/bing-code-samples?view=foundry-classic&pivots=python
**To Reproduce use this code**
import os
from dotenv import load_dotenv
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential
from azure.ai.agents.models import BingGroundingTool
load_dotenv()
project_endpoint = os.environ["PROJECT_ENDPOINT"]
# Create an AIProjectClient instance
project_client = AIProjectClient(
endpoint=project_endpoint,
credential=DefaultAzureCredential() # Use Azure Default Credential for authentication
)
conn_id = os.environ["BING_CONNECTION_ID"]
# Initialize the Bing Grounding tool
bing = BingGroundingTool(connection_id=conn_id)
with project_client:
# Create an agent with the Bing Grounding tool
agent = project_client.agents.create_agent(
model=os.environ["MODEL_DEPLOYMENT_NAME"], # Model deployment name
name="my-agent1", # Name of the agent
instructions="You are a helpful agent", # Instructions for the agent
tools=bing.definitions, # Attach the Bing Grounding tool
)
print(f"Created agent, ID: {agent.id}")
# Create a thread for communication
thread = project_client.agents.threads.create()
print(f"Created thread, ID: {thread.id}")
# Add a message to the thread
message = project_client.agents.messages.create(
thread_id=thread.id,
role="user", # Role of the message sender
content="What is the weather in Seattle today?", # Message content
)
print(f"Created message, ID: {message['id']}")
# Create and process an agent run
run = project_client.agents.runs.create_and_process(
thread_id=thread.id,
agent_id=agent.id,
# tool_choice={"type": "bing_grounding"} # optional, you can force the model to use Grounding with Bing Search tool
)
print(f"Run finished with status: {run.status}")
# Check if the run failed
if run.status == "failed":
print(f"Run failed: {run.last_error}")
# Fetch and log all messages
messages = project_client.agents.messages.list(thread_id=thread.id)
for message in messages:
print(f"Role: {message.role}, Content: {message.content}")
project_client.agents.delete_agent(agent.id)
print("Deleted agent")
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Additional context**
Add any other context about the problem here.
Contributor guide
Assessment
This issue has not been assessed yet.