[Feature Request]: Whether autogen-studio supports exposing the workflow API for external applications
Is your feature request related to a problem? Please describe.
Whether autogen-studio supports exposing the workflow API for external applications?This will be very useful
Describe the solution you'd like
No response
Additional context
No response
Good question! @victordibia and @JingyaChen do we have this plan? It sounds like a very useful feature to have!
Hi @shanmu-raoyunfei ,
Great question. Yes, we have documentation here that shows how you can export your workflow as json and then import it in your python application using the workflow api.
- https://microsoft.github.io/autogen/docs/autogen-studio/usage#export-workflow
- https://microsoft.github.io/autogen/docs/autogen-studio/faqs#q-can-i-export-my-agent-workflows-for-use-in-a-python-app
}
from autogenstudio import WorkflowManager
# load workflow from exported json workflow file.
workflow_manager = WorkflowManager(workflow="path/to/your/workflow_.json")
# run the workflow on a task
task_query = "What is the height of the Eiffel Tower?. Dont write code, just respond to the question."
workflow_manager.run(message=task_query)
The workflow can be launched as an API endpoint from the command line using the autogenstudio commandline tool.
autogenstudio serve --workflow=workflow.json --port=5000
@shanmu-raoyunfei , does this address the needs you are describing? Note: There may be slight changes to the api in the future.
This will solve some of my problems. It would be nice to have direct access to workflow as an API endpoint. Running this workflow from the command line or from a separate application is cumbersome. Thank you very much for your reply
I am having trouble as well with using workflow API in a python code.
There are two things here:
- When I configured a model, An agent, A workflow and tested in the playground the results were amazing, but when I tried to export the workflow and use in a sample python code. It's just printing below:
python spellingbee.py role='assistant' content='' meta={'messages': [], 'summary_method': 'none', 'time': 1.9073486328125e-06, 'files': [], 'task': 'What is the height of the Eiffel Tower?. Dont write code, just respond to the question.'} id=None created_at=datetime.datetime(2024, 7, 7, 13, 11, 27, 604561) updated_at=datetime.datetime(2024, 7, 7, 13, 11, 27, 604564) user_id=None session_id=None connection_id=None []After that I inspected the workflow json file and it has no information other than metadata. I am not sure how did that happened.
from autogenstudio import WorkflowManager
# load workflow from json file
workflow_manager = WorkflowManager(workflow="Spelling-bee-Workflow.json")
# run the workflow on a task
task_query = "What is the height of the Eiffel Tower?. Dont write code, just respond to the question."
result = workflow_manager.run(message=task_query)
print(result)
history = workflow_manager.agent_history
print(history)
Spelling-bee-Workflow.json
{"user_id":"[email protected]","version":"0.0.1","name":"Hacker News Workflow","description":"Hacker News Workflow","type":"sequential","summary_method":"none","sample_tasks":[]}
A Snapshot from Spelling-bee playground session
- The Second thing I've tried
autogenstudio serve --workflow=workflow.json --port=5000as well but I couldn't figure out the request body (would be beneficial for beginners to have a small section in the documentation). If I figure out before anyone support me, I will contribute for the documentation of it.
Hoping to get some help from the community or maintainers.
Thank you for all for your hard work. -Chandra
@shanmu-raoyunfei ,
Thats a good point. AutoGen Studio actually exposes the API end point that is used by the UI. The API endpoint is built using FastAPI and you can review the docs by
autogenstudio ui --port 8081 --docs
Then go to http://localhost:8081/api/docs
In AGS, tasks are run within sessions and the endpoint for this is /sessions/{session_id}/workflow/{workflow_id}/run . You can also look at the frontend code to see how this api is called from the frontend.
@sekharmalla ,
Thanks for mentioning this. The behavior here is still being improved. There are currently two ways to download a workflow (which should be merged into one). The download button on the card has only the workflow definition. However, if you click export (see documentation here), there a download button that exports the entire workflow (with agents, skills, models etc). That is the workflow that can be integrated with code or command line etc.
The serve command uses a relatively simple FastAPI implementation (code here) and if you go to the url of the app :5000/docs this should describe the api endpoint.
@victordibia Thanks for that example of loading a workflow from JSON. However, I was wondering how to populate the system_message of the agents in a workflow with template variables for any run-time data? For example, if the system_message for one of the agents is:
You are a helpful assistant. Today's date is {today}.
Before I invoke workflow_manager.run , this prompt template variable {today} needs to be replace with its actual value. What is the recommended way for doing that?
Shouldn't the run method accept a dictionary of run-time data to populate prompt templates?
Closing add addressed.