Hello @桂學文 Kevin Kuei ,
Yes, you can get the agents, threads and messages using python sdk.
Check this documentation where you can use azure-ai-agents
or azure-ai-projects
package.
Below is the sample code using azure-ai-projects
package with AIProjectsClient
.
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential
project_client = AIProjectClient(endpoint="Foundry-based-project-endpoint", credential=DefaultAzureCredential())
agents = list(project_client.agents.list_agents())
threads = list(project_client.agents.threads.list())
messages = list(project_client.agents.messages.list(threads[0].id))
Above code gets agents, threads and messages based on thread id.
user_messages = [msg for msg in messages if msg.get("role") == "user"]
assistant_messages = [msg for msg in messages if msg.get("role") == "assistant"]
print("User Messages:")
for msg in user_messages:
print(msg.content)
print("\nAssistant Messages:")
for msg in assistant_messages:
print(msg.content)
Output:
Customize the above code for you use case.
If the solution helped you do accept and give feedback clicking on yes.
Thank you