article_icon
article

Function Group Sharing: Collaboration and Visibility

AI Engine API and Python SDK feature that allows you to share function groups with other users

2024-09-057 min readFetch.ai

Overview

We have a new enhancement in AI Engine API and Python SDK that allows you to grant access to your

code-icon
code-icon
function groups
in one easy step, streamlining collaboration and making it possible to share resources within a defined set of users while keeping absolute control over your resources.

With it, you will be able to provide access but keep everybody away from altering the core functionalities of your app.

Why This Feature Matters

Collaboration

Collaboration is at the heart of innovation. Whether you're working on a complex project, sharing agents with colleagues, or simply need to grant access to specific functionalities, our new function group-sharing feature makes it effortless.

Visibility

There are not a few occasions when we need to make our resources, in this case, our

code-icon
code-icon
agents
or
code-icon
code-icon
functions
, accessible for certain people. But "accessible" means that it can be used and reached easily, not altered in any way - which is not a minor thing.

This is what you get with the Function Group Sharing feature.

The use cases are infinite and they will depend entirely on your requirements - from sharing a bunch of agents used only by your brand new company project with the QA team to sharing your personal agents that replicate Nancy Pelosi's trades in the stock market within your colleagues (and not allowing them to alter it - but get the latest updates).

How It Works

Sharing a Function Group via the AI Engine API

With this new feature, you can share a function group with another user by making a single API request. Here’s how you can do it:

code-icon
code-icon
import asyncio 
import json
import aiohttp  

async def share_function_group(
	fg_id: str, 
	target_user_email: str, 
	api_key: str
):
	###
	# THE RELEVANT PART
	###

	"""
		I will explain the action part a bit more after this snippet :)
		Just keep in mind that "SHARE" means giving access, so the only
		allowed action by user you are sharing it with should be
		"RETRIEVE" (or, in other words, action that cannot alter any of your 
		share resources).
	"""
	payload = {  
	    "user_email_to_add_permission": target_user_email,  
	    "action": "RETRIEVE"
	}
	headers = {  
	    "Content-Type": "application/json",  
	    "Authorization": f"Bearer {api_key}"  
	}
	method = "PUT"
	
	async with aiohttp.ClientSession() as session:  
	    async with session.request(
		    method, 
		    f"{api_base_url}{endpoint}",
		    headers=headers,
		    data=json.dumps(payload)
	    ) as response:  
		
		# If everything went ok: -> status=201 & empty body
        return response.status 

###
# DISPENSABLE PART, IT IS HERE JUST FOR THE SAKE OF THE EXAMPLE.
###
if __name__ == "__main__":
	asyncio.run(
		share_function_group(     
			fg_id="your_function_group_id",
			target_user_email="[email protected]",
			api_key="an agentverse api key"
		)
	)

The "actions" key refers to what kind of operations will be able to commit the user granted with.

For example, in a general sense - when we "share" we intend to allow somebody to enjoy our resources but do not alter them at all (destroy, change, or share with other people with our permission).

The owner of

code-icon
code-icon
function group
will be able to provide as many permissions as he wishes but somebody who received
code-icon
code-icon
RETRIEVE
permission won't be able, actually won't be able to do anything except use those resources related to the
code-icon
code-icon
function group
in question.

Using the Python SDK

If you're already using our Python SDK, sharing a function group is a breeze.

🧠 If you are any curious or want to delve into our SDK, please, visit https://fetch.ai/docs/guides/ai-engine-sdk/python to know more.

In case this will be the first time you use the SDK be sure to follow the README before you start to experiment with the following snippets and tools in order to have a working and sounding setup.

📢 We also have JS SDK 🛠️

Option 1: Sharing Function Group tool (scripts for discretionary use)

If you are not interested in adding this programmatically or adding it to a bigger project you can just use a script meant for this purpose, so the only thing you will have to do to get your function-group shared is to execute it.

You will find it in

code-icon
code-icon
examples/share_function_group.py

Once the SDK setup is ready - using that tool is as easy as running it with our Python interpreter. Let’s see the parameters accepted by the script:

  • --function_group_id_to_share (or -fg_id_to_share): It's self-explanatory, it will be the identifier of the

    code-icon
    code-icon
    function group
    that we wish to share with somebody else.

    You could retrieve that identifier by using the SDK lib or just another useful tool we have provided for cases like that:

    code-icon
    code-icon
    examples/list_function_groups_by_user_sdk.py

  • --target_environment (or -e): That parameter is meant to define which environment (agentverse's cluster we could say) we want to affect; production, staging, development...

    This is unlikely to be used or has much relevance for the general audience and use cases, so you can omit that argument and it will automatically point to production.

  • --target_user_email: As self-explanatory as the previous ones, this is the email of the user with whom we want to share the

    code-icon
    code-icon
    function group
    .

Resulting in something like the following:

code-icon
code-icon
# Located in the "ai-engine-sdk-py" root
python examples/share_function_group.py -fg_id_to_share "bcd181fa-14dd-4d94-8094-c9b4c085e8aa" -target_user_email "[email protected]"

Option 2: Using the SDK (the lib itself)

The SDK handles all the underlying API interactions for you, allowing you to focus on what matters most: your project, your logic.

Here is a dummy, but functional, example.

code-icon
code-icon
import argparse 
import asyncio 
from ai_engine_sdk import AiEngine

async def main(fg_id: str, api_key: str, target_user_email: str):
	###
	# THE RELEVANT PART
	###
	client = AiEngine(api_key=api_key)
	result = await client.share_function_group(
		function_group_id=fg_id,
		target_user_email=target_user_email
	)
	
	###
	# SECONDARY ELEMENTS FOR THE SAKE OF THE EXAMPLE AND TOTALLY DISPENSABLE
	###
	print(result)  
	if __name__ == "__main__":
		parser = argparse.ArgumentParser()
		parser.add_argument(
			"--fg_id", 
			required=True, 
			help="Function group ID to share"
		) 
		parser.add_argument(
			"--email", 
			required=True,
			help="Target user's email; with whom I want to share."
		)
		parser.add_argument(
			"--api_key", 
			required=True, 
			help="Your AgentVerse API key"
		)
		args = parser.parse_args()
		asyncio.run(
			main(
			fg_id=args.fg_id, 
			api_key=args.api_key,
			target_user_email=args.email
			)
		)

As you can see, is as simple as using a single method of the client and providing the

code-icon
code-icon
function group
you wish to share and the email of whom you want to share it!

Key Features

  • Simple Sharing: Share function groups with a single API call or SDK method.
  • Secure Access Control: Only authorized users can access shared function groups, hence functions and agents in it, while ensuring your data remains secure.
  • Flexible Integration: Easily integrate this feature into your existing workflows and scripts with minimal effort.

Use Cases

1. Collaborative Development

Imagine you're part of a team working on an agent (or a bunch of them with a common goal). You’ve created a function group that encapsulates several critical functions. With this new feature, you can quickly share the function group with your teammates, allowing them to contribute without needing to duplicate your work.

2. Permission Management for Enterprise Applications

In a large enterprise environment, managing permissions across different teams can be complex. This feature allows you to efficiently grant access to specific function groups, ensuring that each team member has the necessary permissions to perform their tasks without compromising security.

3. Educational Purposes

Educators can now easily share function groups with students. This is particularly useful for coding boot camps, data science courses, or any learning environment where instructors need to provide specific resources to students.

Get Started Today!

Whether you’re sharing resources with a teammate or managing access for an entire department, this enhancement is designed to make your life easier.


For any questions or feedback, feel free to reach out to our support team or join the conversation on our community forum. Happy coding! 🎉

Stay tuned for more updates as we continue to improve our platform with new and exciting features.


More from Fetch