Skip to content
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

fire studio initial commit #2

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
38 changes: 29 additions & 9 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
from typing import Any, Awaitable, Callable, Dict, List, Literal, Optional, Tuple, Type, TypeVar, Union

from .. import OpenAIWrapper
from ..code_utils import DEFAULT_MODEL, UNKNOWN, content_str, execute_code, extract_code, infer_lang
from ..code_utils import (
DEFAULT_MODEL,
UNKNOWN,
content_str,
execute_code,
execute_code_from_work_dir,
extract_code,
infer_lang,
)
from ..function_utils import get_function_schema, load_basemodels_if_needed, serialize_to_str
from .agent import Agent
from .._pydantic import model_dump
Expand Down Expand Up @@ -1469,16 +1477,16 @@ def execute_function(self, func_call, verbose: bool = False) -> Tuple[bool, Dict
func_name = func_call.get("name", "")
func = self._function_map.get(func_name, None)

input_string = self._format_json_str(func_call.get("arguments", "{}"))
try:
arguments = json.loads(input_string)
except json.JSONDecodeError as e:
arguments = None
content = f"Error: {e}\n You argument should follow json format."

is_exec_success = False
if func is not None:
# Extract arguments from a json-like string and put it into a dict.
input_string = self._format_json_str(func_call.get("arguments", "{}"))
try:
arguments = json.loads(input_string)
except json.JSONDecodeError as e:
arguments = None
content = f"Error: {e}\n You argument should follow json format."

# Try to execute the function
if arguments is not None:
print(
Expand All @@ -1490,8 +1498,20 @@ def execute_function(self, func_call, verbose: bool = False) -> Tuple[bool, Dict
is_exec_success = True
except Exception as e:
content = f"Error: {e}"
elif func_name == "python":
exitcode, content = self.execute_code_blocks([("python", func_call.get("arguments", "{}"))])
if exitcode != 0:
is_exec_success = False
else:
content = f"Error: Function {func_name} not found."
try:
content = execute_code_from_work_dir(
self._code_execution_config["work_dir"] + "/skills.py", func_name, arguments
)
is_exec_success = True
except KeyError:
content = f"Error: Function {func_name} not found."
except Exception as e:
content = f"Error: {e}"

if verbose:
print(
Expand Down
11 changes: 10 additions & 1 deletion autogen/code_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import time
from concurrent.futures import ThreadPoolExecutor, TimeoutError
from hashlib import md5
from typing import Callable, Dict, List, Optional, Tuple, Union
from typing import Any, Callable, Dict, List, Optional, Tuple, Union

from autogen import oai

Expand Down Expand Up @@ -636,3 +636,12 @@ def implement(
# cost += metrics["gen_cost"]
# if metrics["succeed_assertions"] or i == len(configs) - 1:
# return responses[metrics["index_selected"]], cost, i


def execute_code_from_work_dir(file_path: str, func_name: str, arguments: Dict[str, Any]) -> Any:
with open(file_path, "r") as file:
code = compile(file.read(), file_path, "exec")
exec(code, globals())

func = globals()[func_name]
return func(**arguments)
15 changes: 12 additions & 3 deletions samples/apps/autogen-studio/autogenstudio/workflowmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def sanitize_agent_spec(self, agent_spec: AgentFlowSpec) -> AgentFlowSpec:
"""

agent_spec.config.is_termination_msg = agent_spec.config.is_termination_msg or (
lambda x: "TERMINATE" in x.get("content", "").rstrip()
lambda x: x.get("content", "")
and "TERMINATE" in x.get("content", "").rstrip()
)
skills_prompt = ""
if agent_spec.skills:
Expand Down Expand Up @@ -139,10 +140,18 @@ def load(self, agent_spec: AgentFlowSpec) -> autogen.Agent:
agent_spec = self.sanitize_agent_spec(agent_spec)
if agent_spec.type == "assistant":
agent = autogen.AssistantAgent(**asdict(agent_spec.config))
agent.register_reply([autogen.Agent, None], reply_func=self.process_reply, config={"callback": None})
agent.register_reply(
[autogen.Agent, None],
reply_func=self.process_reply,
config={"callback": None},
)
elif agent_spec.type == "userproxy":
agent = autogen.UserProxyAgent(**asdict(agent_spec.config))
agent.register_reply([autogen.Agent, None], reply_func=self.process_reply, config={"callback": None})
agent.register_reply(
[autogen.Agent, None],
reply_func=self.process_reply,
config={"callback": None},
)
else:
raise ValueError(f"Unknown agent type: {agent_spec.type}")
return agent
Expand Down
25 changes: 25 additions & 0 deletions samples/apps/fireworks-studio/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
database.sqlite
.cache/*
firestudio/web/files/user/*
firestudio/web/files/ui/*
OAI_CONFIG_LIST
scratch/
firestudio/web/workdir/*
firestudio/web/ui/*
firestudio/web/skills/user/*
.release.sh

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
.virtual_documents/*
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@



import json

from firestudio import AgentWorkFlowConfig, AutoGenWorkFlowManager
import uuid
import os

work_dir = f"/tmp/{uuid.uuid4()}"
if not os.path.exists(work_dir):
os.makedirs(work_dir)

# load an agent specification in JSON
agent_spec = json.load(open("agent_spec.json"))

# Creat a An AutoGen Workflow Configuration from the agent specification
agent_work_flow_config = AgentWorkFlowConfig(**agent_spec)

# Create a Workflow from the configuration
agent_work_flow = AutoGenWorkFlowManager(agent_work_flow_config, work_dir=work_dir)

# Run the workflow on a task
task_query = "Compare the stock price of nvidia and supermicro over the past 1 year and plot a chart with their prices."
agent_work_flow.run(message=task_query, clear_history=True)



5 changes: 5 additions & 0 deletions samples/apps/fireworks-studio/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
recursive-include firestudio/web/ui *
recursive-exclude notebooks *
recursive-exclude frontend *
recursive-exclude docs *
recursive-exclude tests *
124 changes: 124 additions & 0 deletions samples/apps/fireworks-studio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# AutoGen Studio
[![PyPI version](https://badge.fury.io/py/autogenstudio.svg)](https://badge.fury.io/py/autogenstudio)
[![Downloads](https://static.pepy.tech/badge/autogenstudio/week)](https://pepy.tech/project/autogenstudio)

![ARA](./docs/ara_stockprices.png)

AutoGen Studio is an AutoGen-powered AI app (user interface) to help you rapidly prototype AI agents, enhance them with skills, compose them into workflows and interact with them to accomplish tasks. It is built on top of the [AutoGen](https://microsoft.github.io/autogen) framework, which is a toolkit for building AI agents.

Code for AutoGen Studio is on GitHub at [microsoft/autogen](https://github.com/microsoft/autogen/tree/main/samples/apps/autogen-studio)

> **Note**: AutoGen Studio is meant to help you rapidly prototype multi-agent workflows and demonstrate an example of end user interfaces built with AutoGen. It is not meant to be a production-ready app.

### Capabilities / Roadmap

Some of the capabilities supported by the app frontend include the following:

- [x] Build / Configure agents (currently supports two agent workflows based on `UserProxyAgent` and `AssistantAgent`), modify their configuration (e.g. skills, temperature, model, agent system message, model etc) and compose them into workflows.
- [x] Chat with agent works and specify tasks.
- [x] View agent messages and output files in the UI from agent runs.
- [x] Add interaction sessions to a gallery.
- [ ] Support for more complex agent workflows (e.g. `GroupChat` workflows).
- [ ] Improved user experience (e.g., streaming intermediate model output, better summarization of agent responses, etc).

Project Structure:

- _autogenstudio/_ code for the backend classes and web api (FastAPI)
- _frontend/_ code for the webui, built with Gatsby and TailwindCSS

### Installation

1. **Install from PyPi**

We recommend using a virtual environment (e.g., conda) to avoid conflicts with existing Python packages. With Python 3.10 or newer active in your virtual environment, use pip to install AutoGen Studio:

```bash
pip install autogenstudio
```

2. **Install from Source**

> Note: This approach requires some familiarity with building interfaces in React.

If you prefer to install from source, ensure you have Python 3.10+ and Node.js (version above 14.15.0) installed. Here's how you get started:

- Clone the AutoGen Studio repository and install its Python dependencies:

```bash
pip install -e .
```

- Navigate to the `samples/apps/autogen-studio/frontend` directory, install dependencies, and build the UI:

```bash
npm install -g gatsby-cli
npm install --global yarn
cd frontend
yarn install
yarn build
```

For Windows users, to build the frontend, you may need alternative commands to build the frontend.

```bash

gatsby clean && rmdir /s /q ..\\autogenstudio\\web\\ui && (set \"PREFIX_PATH_VALUE=\" || ver>nul) && gatsby build --prefix-paths && xcopy /E /I /Y public ..\\autogenstudio\\web\\ui

```

### Running the Application

Once installed, run the web UI by entering the following in your terminal:

```bash
autogenstudio ui --port 8081
```

This will start the application on the specified port. Open your web browser and go to `http://localhost:8081/` to begin using AutoGen Studio.

Now that you have AutoGen Studio installed and running, you are ready to explore its capabilities, including defining and modifying agent workflows, interacting with agents and sessions, and expanding agent skills.

## Capabilities

AutoGen Studio proposes some high-level concepts.

**Agent Workflow**: An agent workflow is a specification of a set of agents that can work together to accomplish a task. The simplest version of this is a setup with two agents – a user proxy agent (that represents a user i.e. it compiles code and prints result) and an assistant that can address task requests (e.g., generating plans, writing code, evaluating responses, proposing error recovery steps, etc.). A more complex flow could be a group chat where even more agents work towards a solution.

**Session**: A session refers to a period of continuous interaction or engagement with an agent workflow, typically characterized by a sequence of activities or operations aimed at achieving specific objectives. It includes the agent workflow configuration, the interactions between the user and the agents. A session can be “published” to a “gallery”.

**Skills**: Skills are functions (e.g., Python functions) that describe how to solve a task. In general, a good skill has a descriptive name (e.g. `generate_images`), extensive docstrings and good defaults (e.g., writing out files to disk for persistence and reuse). You can add new skills AutoGen Studio app via the provided UI. At inference time, these skills are made available to the assistant agent as they address your tasks.

AutoGen Studio comes with 3 example skills: `fetch_profile`, `find_papers`, `generate_images`. The default skills, agents and workflows are based on the [dbdefaults.json](autogentstudio/utils/dbdefaults.json) file which is used to initialize the database.

## Example Usage

Consider the following query.

```
Plot a chart of NVDA and TESLA stock price YTD. Save the result to a file named nvda_tesla.png
```

The agent workflow responds by _writing and executing code_ to create a python program to generate the chart with the stock prices.

> Note than there could be multiple turns between the `AssistantAgent` and the `UserProxyAgent` to produce and execute the code in order to complete the task.

![ARA](./docs/ara_stockprices.png)

> Note: You can also view the debug console that generates useful information to see how the agents are interacting in the background.

<!-- ![ARA](./docs/ara_console.png) -->

## FAQ

**Q: Where can I adjust the default skills, agent and workflow configurations?**
A: You can modify agent configurations directly from the UI or by editing the [dbdefaults.json](autogentstudio/utils/dbdefaults.json) file which is used to initialize the database.

**Q: If I want to reset the entire conversation with an agent, how do I go about it?**
A: To reset your conversation history, you can delete the `database.sqlite` file. If you need to clear user-specific data, remove the relevant `autogenstudio/web/files/user/<user_id_md5hash>` folder.

**Q: Is it possible to view the output and messages generated by the agents during interactions?**
A: Yes, you can view the generated messages in the debug console of the web UI, providing insights into the agent interactions. Alternatively, you can inspect the `database.sqlite` file for a comprehensive record of messages.

## Acknowledgements

AutoGen Studio is Based on the [AutoGen](https://microsoft.github.io/autogen) project. It was adapted from a research prototype built in October 2023 (original credits: Gagan Bansal, Adam Fourney, Victor Dibia, Piali Choudhury, Saleema Amershi, Ahmed Awadallah, Chi Wang).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions samples/apps/fireworks-studio/firestudio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .chatmanager import *
from .workflowmanager import *
from .datamodel import *
Loading