Agents talk With Your Friends in Your Telegram — CrewAI — 3 Step

Onur ULUSOY
2 min readApr 24, 2024

--

let enable your telegram account to AI agents for talking with your friends as you

Introduction

let enable your telegram account to AI agents for talking with your friends as you

- CrewAI Autonomous AI Agents is an good designed and easy to use agent framework.

- Tiger is an chip to your agents that enables to making real world operations by thinking, just like Neuralink.

TL;DR: This post is about connecting telegram to your CrewAI agents with Tiger library. After that your agent can easily read your messages and write answers

Installing Requirements

For this operation we’ll need the CrewAI and Upsonic libraries.

pip3 instal crewai 'crewai[tools]' langchain-openai upsonic

Imports

from crewai import Agent, Task, Crew, Process
from langchain_openai import ChatOpenAI
from upsonic import Tiger

Connecting to telegram

In this point we will use the [Tiger](https://github.com/Upsonic/Tiger) its an function hub for ai agents, and its have a ready-to-use telegram interface for our agent. Also its have search-engines, code-interpreters and more.

Tiger().get(
"communication.telegram.as_user.signin__user"
)()

Creating Agents

Now we will make **OpenAI Connection**. In this point we will use `gpt-4–0125-preview` for more context.

OPENAI_API_KEY = "sk-" # Your openai api key

llm = ChatOpenAI(
model="gpt-4-0125-preview",
api_key=OPENAI_API_KEY
)
# Captain agent for managing mission
captain = Agent(
role="You are the captain of mission",
goal="Managing the crew for complating mission as want",
backstory="You are graduated from Captaining section of University",
verbose=True,
allow_delegation=False,
llm=llm
)

# Planner agent for generating a plan for mission
planner = Agent(
role="The great plan master in the World",
goal="Generating plans for mission",
backstory="You are graduated from Planning section of University",
verbose=True,
allow_delegation=False,
llm=llm
)

# Executor agent for making executions for mission
executor = Agent(
role="The great executor in the World",
goal="Executing plan and complating the mission",
backstory="You are graduated from Executing section of University",
verbose=True,
allow_delegation=False,
llm=llm
)

Connecting to Tiger and run

In this stage we will give writing answers to incoming messages task and connecting to Tiger.

tools = Tiger().crewai()

telegram_task = Task(
description="""
Writing friendly and solution-focus answers.
For unreaded messages in telegram.
Read the last messages and answer them.
Please answer as a normal human.
You can make many think with your functions also.
""",
expected_output="I write to this, this and this.",
agent=captain
tools=tools
)

Let’s kick off

crew = Crew(
agents=[captain, planner, executor],
tasks=[telegram_task],
verbose=2,
)


result = crew.kickoff()
print(result)

--

--

Onur ULUSOY

I am developer on the this area: Pyhton, Django, Java, WEB and the smilar areas.