Skip to content

Handle requires_action status #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion app/function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
input_queue_name = "input"
output_queue_name = "output"

def get_weather():
# Example implementation of get_weather function
return "sunny"

# Function to initialize the agent client and the tools Azure Functions that the agent can use
def initialize_client():
# Create a project client using the connection string from local.settings.json
Expand Down Expand Up @@ -98,6 +102,19 @@ def prompt(req: func.HttpRequest) -> func.HttpResponse:
time.sleep(1)
run = project_client.agents.get_run(thread_id=thread.id, run_id=run.id)

if run.status == "requires_action":
weather = get_weather()
project_client.agents.submit_tool_outputs_to_run(
thread_id=thread.id,
run_id=run.id,
tool_outputs=[
{
"tool_call_id": run.required_action.submit_tool_outputs.tool_calls[0].id,
"output": weather
}
]
)

if run.status not in ["queued", "in_progress", "requires_action"]:
break

Expand All @@ -107,7 +124,7 @@ def prompt(req: func.HttpRequest) -> func.HttpResponse:
logging.error(f"Run failed: {run.last_error}")

# Get messages from the assistant thread
messages = project_client.agents.get_messages(thread_id=thread.id)
messages = project_client.agents.list_messages(thread_id=thread.id)
logging.info(f"Messages: {messages}")

# Get the last message from the assistant
Expand Down
2 changes: 1 addition & 1 deletion app/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
# Manually managing azure-functions-worker may cause unexpected issues

azure-functions
azure-ai-projects==1.0.0b2
azure-ai-projects==1.0.0b4
azure-storage-queue
azure-identity