Create Issues from Code Commits - using Autogen
Published: 2024-03-27 10:29:56

---
title: Create Issues from Code Commits - using Autogen
published: true
date: 2024-03-27 05:45:17 UTC
tags: 
canonical_url: https://blog.composio.dev/automating-task-creation-with-openai-assistant-from-code-comments-to-linear-issues/
---

 ![Create Issues from Code Commits - using Autogen](https://blog.composio.dev/content/images/2024/03/SCR-20240327-jlrv.png)

[Join our Discord Community](https://discord.gg/XMa3eWKkH8?ref=blog.composio.dev) and [check out what we're building](https://docs.composio.dev/?ref=blog.composio.dev)!

### <u>Introduction</u>

I use  **`#TODO` comments in commit messages** to **flag future tasks**. **Tracking** these tasks **manually** is **inefficient** and error-prone.

Let's try to build using **Autogen Agents** - Convert these **TODOs from Github code commits into Linear tasks**.

### <u>Background</u>

**Autogen Agentic Framework**  allows for natural language understanding and action-taking and is super easy to start with.

**Composio** is a very easy way to connect your Autogen Agents with real life tools. We will be using it to connect our agent to Linear and Github.

TL;DR: [<u>Show me the Code</u>](https://blog.composio.dev/automating-task-creation-with-openai-assistant-from-code-comments-to-linear-issues#final-code)

### **<u>Setup</u>**

```
!pip install pyautogen composio_autogen --quiet

```

_Installing the relevant packages_

### <u>Initialising Agents</u>

To initialise, perform the following steps:

1. **Configure LLM:** Use the `gpt-4-1106-preview` model. Provide the OpenAI environment key through an environment variable or modify the code directly.
2. **Set Up Assistant Agent:** Create it with a system prompt and the LLM configuration. Adjust as needed to improve outcomes.
3. **Establish User Proxy Agent:** These agents simulate users, interacting with Autogen agents. They include a function to end the process upon detecting the word "Terminate," as specified in the system prompt.

```
import os

from autogen import AssistantAgent, UserProxyAgent

from composio_autogen import App, Action, ComposioToolset

llm_config = {
    "config_list": [
        {
            "model": "gpt-4-1106-preview",
            "api_key": os.environ.get(
                "OPENAI_API_KEY", "sk-123131 ****"
            ),
        }
    ]
}

super_agent = AssistantAgent(
    "chatbot",
    system_message="""You are a super intelligent personal assistant.
    You have been given a set of tools that you are supposed to choose from.
    You decide the right tool and execute it to achieve your task.
    Reply TERMINATE when the task is done or when user's content is empty""",
    llm_config=llm_config,
)

# create a UserProxyAgent instance named "user_proxy"
user_proxy = UserProxyAgent(
    "user_proxy",
    is_termination_msg=lambda x: x.get("content", "")
    and "TERMINATE" in x.get("content", ""),
    human_input_mode="NEVER", # Don't take input from User
    code_execution_config={"use_docker": False},
)
```

_Agent Initialisation Code_

### <u>Powering agents with Tools</u>

We need to connect Github and linear to our agents and via function calling they ideally accomplish the task. I will be using `Composio` to do that.

1. Authorise `Github` and `Linear` connections, so Autogen Agents can interact with it. 

```
pip install composio-autogen

composio-cli add github # Authorise Github 

composio-cli add linear # Authorise Linear 
```

_Adding Github and Linear Connections to Composio. (Run on Terminal)_

1. Register the tools with Autogen Agent

```
# Initialise the Composio Tool Set
composio_tools = ComposioToolset()

# Register the authorised Applications, with our agent.
composio_tools.register_tools(
    tools=[App.LINEAR, App.GITHUB], caller=super_agent, executor=user_proxy
)
```

_This allows our agent and user proxy to interact with external Applications_

### <u>Executing the Task</u>

Define the task so agent can execute it. 🚀

```
task = """For all the todos in my last commit of SamparkAI/Docs,
create a linear issue on project name hermes board and assign to right person"""

response = user_proxy.initiate_chat(super_agent, message=task)

print(response.chat_history)
```

_And it works!_

```
The issues have been successfully created on the Linear board for the project "Hermes" as follows:

1. **Extracted TODO from Docs commit**
   - Issue ID: `d578a113-a7ab-4084-9a76-5dbbd4f23b21`
   - Description: A new Linear issue created for the TODO from the latest commit in the SamparkAI/Docs repository.

2. **Evaluate documentation structure**
   - Issue ID: `0c710f8a-8037-4bf4-8ebd-a801531117b5`
   - Description: Evaluate and update the documentation structure based on the latest standards.

3. **Review and finalize API docs**
   - Issue ID: `961651df-ad3c-4b4c-b162-931eead8be19`
   - Description: Review the API documentation to ensure accuracy and completeness.

All issues have been assigned to the appropriate team member. The task is now complete.

Terminate
```

_Output From Autogen_

### <u>Final Code</u>

[DeepNote Link](https://deepnote.com/workspace/composio-f87d-8ad9f1f9-a21a-4462-a4bb-174bde78f67a/project/Welcome-to-Deepnote-1e32fad6-0d9e-482b-b46d-08f868445ba6/notebook/Autogen%20Agent-cfb9253cd2c24de587bef8f7c6341c59?ref=blog.composio.dev)

```
#!pip install pyautogen composio_autogen --quiet

from autogen import AssistantAgent, UserProxyAgent
from composio_autogen import App, Action, ComposioToolset
import os

llm_config = {
    "config_list": [
        {
            "model": "gpt-4-turbo-preview",
            "api_key": os.environ.get("OPENAI_API_KEY", "sk-123***"),
        }
    ]
}

super_agent = AssistantAgent(
    "chatbot",
    system_message="""You are a super intelligent personal assistant.
    You have been given a set of tools that you are supposed to choose from.
    You decide the right tool and execute it to achieve your task.
    Reply TERMINATE when the task is done or when user's content is empty""",
    llm_config=llm_config,
)

# create a UserProxyAgent instance named "user_proxy"
user_proxy = UserProxyAgent(
    "user_proxy",
    is_termination_msg=lambda x: x.get("content", "")
    and "TERMINATE" in x.get("content", ""),
    human_input_mode="NEVER", # Don't take input from User
    code_execution_config={"use_docker": False},
)

# Initialise the Composio Tool Set
composio_tools = ComposioToolset()

# Register the preferred Applications, with right executor.
composio_tools.register_tools(
    tools=[App.LINEAR, App.GITHUB], caller=super_agent, executor=user_proxy
)

task = """For all the todos in my last commit of SamparkAI/Docs,
create a linear issue on project name hermes board and assign to right person"""

response = user_proxy.initiate_chat(super_agent, message=task)

print(response.chat_history)

```

_Complete Code_

[Join our Discord Community](https://discord.gg/XMa3eWKkH8?ref=blog.composio.dev) and [check out what we're building](https://docs.composio.dev/?ref=blog.composio.dev)!