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

Add AgentGPT pip package #1651

Draft
wants to merge 2 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
48 changes: 48 additions & 0 deletions agentgpt_pip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# AgentGPT Pip Package

This directory contains the pip package for AgentGPT. The package provides tools and utilities for using AgentGPT for custom code.

## Installation

To install the AgentGPT pip package, run the following command:

```bash
pip install agentgpt
```

## Usage

After installing the package, you can use the argument tools provided by AgentGPT. Below are some examples of how to use the package.

### Example 1: Running a Task

```python
from agentgpt import main

main(["--task", "example_task"])
```

### Example 2: Using Argument Tools

```python
from agentgpt.arg_tools import parse_arguments, handle_arguments

args = parse_arguments(["--task", "example_task", "--config", "config.yaml"])
handle_arguments(args)
```

## Contributing

We welcome contributions to the AgentGPT pip package. To contribute, please follow these steps:

1. Fork the repository.
2. Create a new branch for your feature or bugfix.
3. Make your changes and commit them with a descriptive message.
4. Push your changes to your fork.
5. Create a pull request to the main repository.

Please ensure that your code adheres to the project's coding standards and passes all tests.

## License

This project is licensed under the MIT License. See the [LICENSE](../LICENSE) file for details.
19 changes: 19 additions & 0 deletions agentgpt_pip/agentgpt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
AgentGPT package initialization.
"""

import argparse
import sys

def main():
parser = argparse.ArgumentParser(description="AgentGPT CLI")
parser.add_argument("--task", type=str, help="Task to perform")
args = parser.parse_args()

if args.task:
print(f"Performing task: {args.task}")
else:
print("No task provided")

if __name__ == "__main__":
main()
33 changes: 33 additions & 0 deletions agentgpt_pip/agentgpt/arg_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Argument tools for custom code in AgentGPT.
"""

import argparse

def parse_arguments():
"""
Parse command-line arguments.

Returns:
argparse.Namespace: Parsed arguments.
"""
parser = argparse.ArgumentParser(description="AgentGPT Argument Tools")
parser.add_argument("--task", type=str, help="Task to perform")
parser.add_argument("--config", type=str, help="Path to configuration file")
return parser.parse_args()

def handle_arguments(args):
"""
Handle parsed arguments.

Args:
args (argparse.Namespace): Parsed arguments.
"""
if args.task:
print(f"Performing task: {args.task}")
if args.config:
print(f"Using configuration file: {args.config}")

if __name__ == "__main__":
args = parse_arguments()
handle_arguments(args)
35 changes: 35 additions & 0 deletions agentgpt_pip/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from setuptools import setup, find_packages

setup(
name="agentgpt",
version="0.1.0",
packages=find_packages(),
install_requires=[
"fastapi>=0.98.0",
"boto3>=1.28.51",
"uvicorn[standard]>=0.22.0",
"pydantic[dotenv]<2.0",
"ujson>=5.8.0",
"sqlalchemy[mypy,asyncio]>=2.0.21",
"aiomysql>=0.1.1",
"mysqlclient>=2.2.0",
"sentry-sdk>=1.31.0",
"loguru>=0.7.2",
"aiokafka>=0.8.1",
"requests>=2.31.0",
"langchain>=0.0.295",
"openai>=0.28.0",
"wikipedia>=1.4.0",
"replicate>=0.8.4",
"lanarky>=0.7.15",
"tiktoken>=0.5.1",
"grpcio>=1.58.0",
"pinecone-client>=2.2.4",
"python-multipart>=0.0.6",
"aws-secretsmanager-caching>=1.1.1.5",
"botocore>=1.31.51",
"stripe>=5.5.0",
"cryptography>=41.0.4",
"httpx>=0.25.0",
],
)
34 changes: 34 additions & 0 deletions agentgpt_pip/tests/test_arg_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import unittest
from agentgpt.arg_tools import parse_arguments, handle_arguments

class TestArgTools(unittest.TestCase):

def test_parse_arguments_with_task(self):
args = parse_arguments(['--task', 'test_task'])
self.assertEqual(args.task, 'test_task')
self.assertIsNone(args.config)

def test_parse_arguments_with_config(self):
args = parse_arguments(['--config', 'test_config'])
self.assertEqual(args.config, 'test_config')
self.assertIsNone(args.task)

def test_handle_arguments_with_task(self):
args = parse_arguments(['--task', 'test_task'])
with self.assertLogs(level='INFO') as log:
handle_arguments(args)
self.assertIn('Performing task: test_task', log.output)

def test_handle_arguments_with_config(self):
args = parse_arguments(['--config', 'test_config'])
with self.assertLogs(level='INFO') as log:
handle_arguments(args)
self.assertIn('Using configuration file: test_config', log.output)

def test_parse_arguments_with_no_args(self):
args = parse_arguments([])
self.assertIsNone(args.task)
self.assertIsNone(args.config)

if __name__ == '__main__':
unittest.main()
17 changes: 16 additions & 1 deletion next/src/components/console/AgentControls.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
import clsx from "clsx";
import React from "react";
import { FaPause, FaPlay, FaStop, FaUndo } from "react-icons/fa";
import { FaPause, FaPlay, FaStop, FaUndo, FaTrash } from "react-icons/fa";
import { ImSpinner2 } from "react-icons/im";

import type { AgentLifecycle } from "../../services/agent/agent-run-model";
import Button from "../Button";
import { AgentApi } from "../../services/agent/agent-api";

type AgentControlsProps = {
disablePlay: boolean;
lifecycle: AgentLifecycle;
handlePlay: () => void;
handlePause: () => void;
handleStop: () => void;
agentApi: AgentApi;
};

const AgentControls = ({
lifecycle,
disablePlay,
handlePlay,
handlePause,
handleStop,
agentApi,
}: AgentControlsProps) => {
const handleDelete = async () => {
await agentApi.deleteAgent();
};

return (
<div className="flex gap-2">
<Button ping={!disablePlay} disabled={disablePlay} onClick={handlePlay}>
Expand All @@ -41,6 +49,13 @@ const AgentControls = ({
>
<FaStop />
</Button>
<Button
disabled={lifecycle === "offline" || lifecycle == "stopped"}
onClick={handleDelete}
enabledClassName={clsx("bg-red-600 hover:bg-red-400")}
>
<FaTrash />
</Button>
</div>
);
};
Expand Down
11 changes: 11 additions & 0 deletions next/src/hooks/useAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { api } from "../utils/api";
export type AgentUtils = {
createAgent: (data: CreateAgentProps) => Promise<PrismaAgent | undefined>;
saveAgent: (data: SaveAgentProps) => void;
deleteAgent: (id: string) => void;
};

export function useAgent(): AgentUtils {
Expand All @@ -33,8 +34,18 @@ export function useAgent(): AgentUtils {
if (status === "authenticated") saveMutation.mutate(data);
};

const deleteMutation = api.agent.deleteById.useMutation({
onSuccess: (id: string) => {
utils.agent.getAll.setData(void 0, (oldData) => oldData?.filter(agent => agent.id !== id));
},
});
const deleteAgent = (id: string) => {
if (status === "authenticated") deleteMutation.mutate(id);
};

return {
createAgent,
saveAgent,
deleteAgent,
};
}
6 changes: 6 additions & 0 deletions next/src/services/agent/agent-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export class AgentApi {
});
}

async deleteAgent(): Promise<void> {
if (!this.agentId) return;
this.props.agentUtils.deleteAgent(this.agentId);
this.agentId = undefined;
}

async getInitialTasks(): Promise<string[]> {
return (await this.post<{ newTasks: string[] }>("/api/agent/start", {})).newTasks;
}
Expand Down
19 changes: 19 additions & 0 deletions tkinter_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import tkinter as tk

def update_label():
label.config(text="Button Clicked!")

# Create the main window
root = tk.Tk()
root.title("Tkinter App")

# Create a label
label = tk.Label(root, text="Hello, Tkinter!")
label.pack(pady=10)

# Create a button
button = tk.Button(root, text="Click Me", command=update_label)
button.pack(pady=10)

# Run the Tkinter main loop
root.mainloop()