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

General View

1

Login into to Telegram

We will make this in your local and with Tiger library. Your session management is on the telethon library but Tiger have a non-async interface to control your telegram.

2

Creating Captain, Planner and Executor Agents

In this step we will create a crew in this type to get more success on talking.

3

Connecting Tiger to Your Agents

At the end we will connect the tiger in just 1-line to your agents for enable telegram access, google search, code run and many other ability.

Installing Requirements

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

pip3 install 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 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)