how to implement a custom tool/task/action/agent ?

Hello there! I would like to add a tool, or whatever fits better for the task, to be able to pass a prompt to dalle, generate an image, and send the image (or the images url) to another part of the workflow. ive found the creating a local tool doc https://docs.composio.dev/introduction/foundations/components/local_tools#adding-a-custom-local-tool-in-python, but i cant make it work. ive even bounced it with claude, but i still cant make it this is what i've currently made
from openai import OpenAI
from composio_openai import ComposioToolSet, App, Action
from composio import action

openai_client = OpenAI(api_key="placeholder")
composio_toolset = ComposioToolSet(api_key="placeholder")

@action(toolname="dalle_image_generator", requires=["openai"])
def generate_image(prompt: str, size: str = "1024x1024", n: int = 1) -> str:
"""
Generate an image using DALL-E based on the given prompt.

Args:
prompt (str): The description of the image to generate.
size (str): The size of the image (default: "1024x1024").
n (int): Number of images to generate (default: 1).

Returns:
str: The URL of the generated image, which can be used to access and display the image.
"""
client = OpenAI(api_key="placeholder")

response = client.images.generate(
prompt=prompt,
n=n,
size=size
)
return client.get_output_string("dalle_image_generator", prompt)


actions = composio_toolset.get_tools(actions=[
Action.GMAIL_SEND_EMAIL,
generate_image
])


assistant_instruction = "You are an assistant managing logo creation and email delivery."
assistant = openai_client.beta.assistants.create(
name="Logo Creation Assistant",
instructions=assistant_instruction,
model="gpt-4",
tools=actions,
)
from openai import OpenAI
from composio_openai import ComposioToolSet, App, Action
from composio import action

openai_client = OpenAI(api_key="placeholder")
composio_toolset = ComposioToolSet(api_key="placeholder")

@action(toolname="dalle_image_generator", requires=["openai"])
def generate_image(prompt: str, size: str = "1024x1024", n: int = 1) -> str:
"""
Generate an image using DALL-E based on the given prompt.

Args:
prompt (str): The description of the image to generate.
size (str): The size of the image (default: "1024x1024").
n (int): Number of images to generate (default: 1).

Returns:
str: The URL of the generated image, which can be used to access and display the image.
"""
client = OpenAI(api_key="placeholder")

response = client.images.generate(
prompt=prompt,
n=n,
size=size
)
return client.get_output_string("dalle_image_generator", prompt)


actions = composio_toolset.get_tools(actions=[
Action.GMAIL_SEND_EMAIL,
generate_image
])


assistant_instruction = "You are an assistant managing logo creation and email delivery."
assistant = openai_client.beta.assistants.create(
name="Logo Creation Assistant",
instructions=assistant_instruction,
model="gpt-4",
tools=actions,
)
thanks in advance for your help!
Composio Docs
Creating a Local Tool - Composio
Composio enables your agents to connect with Various Tools and work with them
3 Replies
stuck-chocolate
stuck-chocolate2w ago
and this is the error that i get
Traceback (most recent call last):
File "c:\Users\Lucas\Documents\Programming\Simbiosis\products\Ai Agent\composio\main.py", line 15, in <module>
@action(toolname="dalle_image_generator", requires=["openai"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lucas\AppData\Local\Programs\Python\Python311\Lib\site-packages\composio\tools\base\runtime.py", line 376, in wrapper
f, request_schema, response_schema, _runs_on_shell = _parse_schemas(
^^^^^^^^^^^^^^^
File "C:\Users\Lucas\AppData\Local\Programs\Python\Python311\Lib\site-packages\composio\tools\base\runtime.py", line 362, in _parse_schemas
return _build_executable_from_args(f=f)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lucas\AppData\Local\Programs\Python\Python311\Lib\site-packages\composio\tools\base\runtime.py", line 295, in _build_executable_from_args
raise InvalidRuntimeAction(
composio.tools.base.runtime.InvalidRuntimeAction: Please provide description for return on runtime action generate_image
Traceback (most recent call last):
File "c:\Users\Lucas\Documents\Programming\Simbiosis\products\Ai Agent\composio\main.py", line 15, in <module>
@action(toolname="dalle_image_generator", requires=["openai"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lucas\AppData\Local\Programs\Python\Python311\Lib\site-packages\composio\tools\base\runtime.py", line 376, in wrapper
f, request_schema, response_schema, _runs_on_shell = _parse_schemas(
^^^^^^^^^^^^^^^
File "C:\Users\Lucas\AppData\Local\Programs\Python\Python311\Lib\site-packages\composio\tools\base\runtime.py", line 362, in _parse_schemas
return _build_executable_from_args(f=f)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lucas\AppData\Local\Programs\Python\Python311\Lib\site-packages\composio\tools\base\runtime.py", line 295, in _build_executable_from_args
raise InvalidRuntimeAction(
composio.tools.base.runtime.InvalidRuntimeAction: Please provide description for return on runtime action generate_image
like-gold
like-gold2w ago
Please change the docstring to
Generate an image using DALL-E based on the given prompt.

:param prompt: The description of the image to generate
:param size: The size of the image (default "1024x1024")
:param n: Number of images to generate (default 1)

:return url: The URL of the generated image, which can be used to access and display the image.
Generate an image using DALL-E based on the given prompt.

:param prompt: The description of the image to generate
:param size: The size of the image (default "1024x1024")
:param n: Number of images to generate (default 1)

:return url: The URL of the generated image, which can be used to access and display the image.
This is the current format we use to read the param and return type description. We will make it more flexible in the future. For documentation, check: https://docs.composio.dev/introduction/foundations/components/local_tools
Composio Docs
Creating a Local Tool - Composio
Composio enables your agents to connect with Various Tools and work with them
stuck-chocolate
stuck-chocolate2w ago
I'll give it a shot. Thanks a lot!