# Configuration file for managing API keys as environment variables
from dotenv import load_dotenv
# Load API key information
load_dotenv()
Copy
True
Copy
# Set up LangSmith tracking. https://smith.langchain.com
# !pip install -qU langchain-teddynote
from langchain_teddynote import logging
# Enter a project name.
logging.langsmith("CH15-Agents")
Copy
Copy
Copy
Copy
Create prompt for Agent
chat_history : Variables that store previous conversations (if you don't support multi-turns, you can omit them)
agent_scratchpad : Variables that the agent temporarily saves
input : User input
Copy
Various LLM lists supporting Tool Calling
You need to set the content below to proceed with the lab.
from langchain.tools import tool
from typing import List, Dict
from langchain_teddynote.tools import GoogleNews
# Tool definition
@tool
def search_news(query: str) -> List[Dict[str, str]]:
"""Search Google News by input keyword"""
news_tool = GoogleNews()
return news_tool.search_by_keyword(query, k=5)
print(f"도구 이름: {search_news.name}")
print(f"도구 설명: {search_news.description}")
Tool name: search_news
Tool description: Search Google News by input keyword
# tools 정의
tools = [search_news]
from langchain_core.prompts import ChatPromptTemplate
from langchain.agents import create_tool_calling_agent
# 프롬프트 생성
# 프롬프트는 에이전트에게 모델이 수행할 작업을 설명하는 텍스트를 제공합니다. (도구의 이름과 역할을 입력)
prompt = ChatPromptTemplate.from_messages(
[
(
"system",
"You are a helpful assistant. "
"Make sure to use the `search_news` tool for searching keyword related news.",
),
("placeholder", "{chat_history}"),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
]
)
# !pip install -qU langchain-ollama==0.1.3
from langchain_anthropic import ChatAnthropic
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_openai import ChatOpenAI
from langchain_ollama import ChatOllama
import os
# GPT-4o-mini
gpt = ChatOpenAI(model="gpt-4o-mini")
# Claude-3-5-sonnet
claude = ChatAnthropic(model="claude-3-5-sonnet-20240620", temperature=0)
# Gemini-1.5-pro-latest
gemini = ChatGoogleGenerativeAI(model="gemini-1.5-pro", temperature=0)
# Llama-3.1-70B-Instruct-Turbo
llama = ChatOpenAI(
base_url="https://api.together.xyz/v1",
api_key=os.environ["TOGETHER_API_KEY"],
model="meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
)
# Llama-3.1
ollama = ChatOllama(model="llama3.1", temperature=0)
from langchain.agents import AgentExecutor
# Running gpt_agent
agent_executor = AgentExecutor(
agent=gpt_agent,
tools=tools,
verbose=True,
handle_parsing_errors=True,
)
result = agent_executor.invoke({"input": "Search for news related to AI investment."})
print("Agent execution results:")
print(result["output"])
Invoking: `search_news` with `{'query':'AI investment' }`
[{'url':'https://news.google.com/rss/articles/CBMiTkFVX3lxTE5xUEdrNHZZclQ4RUNmNGpqZG1COUNfckVOZ2hqQTJ4NGkwa0NRU0Q1azRQNzMwTTBJVDloQmNKamRZc3dic0plQWtEUTNXUQ?oc=5','content':'AI investment increase carrier, frequency reassignment burden -Telecommunications' }, {'url':'https://news.google.com/rss/articles/CBMiU0FVX3lxTFB1VDRjTlIxeHRjV3NKaERHMFJLOFNpUlNUVnZzQ0JvOUpISVE2cW9rbTZPVU9lQXZuUURJNHF0aDZyaDdQM0F5NFhsc0NrN1dHNEZz?oc=5','content':'Global CEOs "In the next 3 years, AI investment·G staff will also be selected" -Companies will only fly investment costs" -AI times'}, {' url':'https://news.google.com/rss/articles/CBMiWkFVX3lxTE5XeGtRRjRyeUFZZng4U2JWMmhZdFczSmR5d0YwbmF3cHpJVjRka2x4ZmRoVjdnaWdLOUdVSjNtN1FqeTBpTmRaUk9IZFFVamhGREZzQloxVmZ3UdIBVEFVX3lxTE9NVllVWHNUTTl1NWFXbHJPRHBEOVRiUTlCUmZtRHVZbXlMSl9MaFFsZUd0Yll0dUJNQk5UWjhfalNVV20tSjl3V01wcWtGSWl1Wk5KSg?oc=5','content':'Amazon·MS is a water source investment... Medical AI Mecca Seattle-Korea Economy'}, {'url':'https://news.google.com/rss/articles/CBMiSEFVX3lxTE9DQnVxNFNuYnBzdDFObDRpM292VHlpcTZNZUtEOUJNVE5KWTROR210NEtfZUszUnp6eWJELUg3SkdQeE80TnhsNA?oc=5','content':'Artificial Enterprise ‘Markvision’, 220 billion scale seriesA com/rss/articles/CBMiWkFVX3lxTE5XeGtRRjRyeUFZZng4U2JWMmhZdFczSmR5d0YwbmF3cHpJVjRka2x4ZmRoVjdnaWdLOUdVSjNtN1FqeTBpTmRaUk9IZFFVamhGREZzQloxVmZ3UdIBVEFVX3lxTE9NVllVWHNUTTl1NWFXbHJPRHBEOVRiUTlCUmZtRHVZbXlMSl9MaFFsZUd0Yll0dUJNQk5UWjhfalNVV20tSjl3V01wcWtGSWl1Wk5KSg?oc=5','content':'Amazon·MS invests in water tankers... Medical AI Mecca Seattle-Korea Economy'}, {'url':'https://news.google.com/rss/articles/CBMiSEFVX3lxTE9DQnVxNFNuYnBzdDFObDRpM292VHlpcTZNZUtEOUJNVE5KWTROR210NEtfZUszUnp6eWJELUg3SkdQeE80TnhsNA?oc=5','content':'Artificial Enterprise ‘Markvision’, 220 billion won scale seriesA< com/rss/articles/CBMiWkFVX3lxTE5XeGtRRjRyeUFZZng4U2JWMmhZdFczSmR5d0YwbmF3cHpJVjRka2x4ZmRoVjdnaWdLOUdVSjNtN1FqeTBpTmRaUk9IZFFVamhGREZzQloxVmZ3UdIBVEFVX3lxTE9NVllVWHNUTTl1NWFXbHJPRHBEOVRiUTlCUmZtRHVZbXlMSl9MaFFsZUd0Yll0dUJNQk5UWjhfalNVV20tSjl3V01wcWtGSWl1Wk5KSg?oc=5','content':'Amazon·MS invests in water tankers... Medical AI Mecca Seattle-Korea Economy'}, {'url':'https://news.google.com/rss/articles/CBMiSEFVX3lxTE9DQnVxNFNuYnBzdDFObDRpM292VHlpcTZNZUtEOUJNVE5KWTROR210NEtfZUszUnp6eWJELUg3SkdQeE80TnhsNA?oc=5','content':'Artificial Enterprise ‘Markvision’, 220 billion won scale seriesA< com/rss/articles/CBMiSEFVX3lxTE9DQnVxNFNuYnBzdDFObDRpM292VHlpcTZNZUtEOUJNVE5KWTROR210NEtfZUszUnp6eWJELUg3SkdQeE80TnhsNA?oc=5','content':'Artificial Enterprise ‘Markvision’, 220 billion won series A+ Attract Investment -Platum'}] The following are recent news related to AI investment: com/rss/articles/CBMiSEFVX3lxTE9DQnVxNFNuYnBzdDFObDRpM292VHlpcTZNZUtEOUJNVE5KWTROR210NEtfZUszUnp6eWJELUg3SkdQeE80TnhsNA?oc=5','content':'Artificial Enterprise ‘Markvision’, 220 billion won series A+ Attract Investment -Platum'}] The following are recent news related to AI investment:
One. [Agency investment increasing carrier, frequency reassignment burden-electronic newspaper] (https://news.google.com/rss/articles/CBMiTkFVX3lxTE5xUEdrNHZZclQ4RUNmNGpqZG1COUNfckVOZ2hqQTJ4NGkwa0NRU0Q1azRQNzMwTTBJVDloQmNKamRZc3dic0plQWtEUTNXUQ?oc=5)
2. [Global CEOs "In the next three years, we will also pick up more AI-invested,·, staff" -Nate News] (https://news.google.com/rss/articles/CBMiU0FVX3lxTFB1VDRjTlIxeHRjV3NKaERHMFJLOFNpUlNUVnZzQ0JvOUpISVE2cW9rbTZPVU9lQXZuUURJNHF0aDZyaDdQM0F5NFhsc0NrN1dHNEZz?oc=5)
3. [MIT economist "Only 5% of jobs will be affected by AI for 10 years...Companies will only fly investment costs" -AI Times] (https://news.google.com/rss/articles/CBMiakFVX3lxTE9BQUtjd3pDS1dXRkZQTlo4Y2w2d2laZFFQRXdsbGlCMFRTcWJYLTNLaksxbFlnYzk3clVnYlFxZF93U2xubXY1VVhBTDQ2SDhLbm9hcDdXQ3prTlJtV0VCYTFINmNRbjR5N3c?oc=5)
4. [Amazon·MS invests in water resources... Medical AI Mecca Seattle-Korea Economy] (https://news.google.com/rss/articles/CBMiWkFVX3lxTE5XeGtRRjRyeUFZZng4U2JWMmhZdFczSmR5d0YwbmF3cHpJVjRka2x4ZmRoVjdnaWdLOUdVSjNtN1FqeTBpTmRaUk9IZFFVamhGREZzQloxVmZ3UdIBVEFVX3lxTE9NVllVWHNUTTl1NWFXbHJPRHBEOVRiUTlCUmZtRHVZbXlMSl9MaFFsZUd0Yll0dUJNQk5UWjhfalNVV20tSjl3V01wcWtGSWl1Wk5KSg?oc=5)
5. [Artificial Enterprise ‘Markvision ’, 220 billion won series A+ Attract Investment-Flatum] (https://news.google.com/rss/articles/CBMiSEFVX3lxTE9DQnVxNFNuYnBzdDFObDRpM292VHlpcTZNZUtEOUJNVE5KWTROR210NEtfZUszUnp6eWJELUg3SkdQeE80TnhsNA?oc=5)
Click each link to read the news article in detail.
Finished chain.
Agent run results:
Here are some recent news related to AI investment:
One. [Agency investment increasing carrier, frequency reassignment burden-electronic newspaper] (https://news.google.com/rss/articles/CBMiTkFVX3lxTE5xUEdrNHZZclQ4RUNmNGpqZG1COUNfckVOZ2hqQTJ4NGkwa0NRU0Q1azRQNzMwTTBJVDloQmNKamRZc3dic0plQWtEUTNXUQ?oc=5)
2. [Global CEOs "In the next three years, we will also pick up more AI-invested,·, staff" -Nate News] (https://news.google.com/rss/articles/CBMiU0FVX3lxTFB1VDRjTlIxeHRjV3NKaERHMFJLOFNpUlNUVnZzQ0JvOUpISVE2cW9rbTZPVU9lQXZuUURJNHF0aDZyaDdQM0F5NFhsc0NrN1dHNEZz?oc=5)
3. [MIT economist "Only 5% of jobs will be affected by AI for 10 years...Companies will only fly investment costs" -AI Times] (https://news.google.com/rss/articles/CBMiakFVX3lxTE9BQUtjd3pDS1dXRkZQTlo4Y2w2d2laZFFQRXdsbGlCMFRTcWJYLTNLaksxbFlnYzk3clVnYlFxZF93U2xubXY1VVhBTDQ2SDhLbm9hcDdXQ3prTlJtV0VCYTFINmNRbjR5N3c?oc=5)
4. [Amazon·MS invests in water resources... Medical AI Mecca Seattle-Korea Economy] (https://news.google.com/rss/articles/CBMiWkFVX3lxTE5XeGtRRjRyeUFZZng4U2JWMmhZdFczSmR5d0YwbmF3cHpJVjRka2x4ZmRoVjdnaWdLOUdVSjNtN1FqeTBpTmRaUk9IZFFVamhGREZzQloxVmZ3UdIBVEFVX3lxTE9NVllVWHNUTTl1NWFXbHJPRHBEOVRiUTlCUmZtRHVZbXlMSl9MaFFsZUd0Yll0dUJNQk5UWjhfalNVV20tSjl3V01wcWtGSWl1Wk5KSg?oc=5)
5. [Artificial Enterprise ‘Markvision ’, 220 billion won series A+ Attract Investment-Flatum] (https://news.google.com/rss/articles/CBMiSEFVX3lxTE9DQnVxNFNuYnBzdDFObDRpM292VHlpcTZNZUtEOUJNVE5KWTROR210NEtfZUszUnp6eWJELUg3SkdQeE80TnhsNA?oc=5)
Click each link to read the news article in detail.
def execute_agent(llm, tools, input_text, label):
agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=False)
result = executor.invoke({"input": input_text})
print(f"[{label}] This is the result.")
if isinstance(result["output"], list) and len(result["output"]) > 0:
for item in result["output"]:
if "text" in item:
print(item["text"])
elif isinstance(result["output"], str):
print(result["output"])
else:
print(result["output"])
query = (
"Please search for news related to AI investment and write the results in the form of an Instagram post."
)
# gpt
execute_agent(gpt, tools, query, "gpt")
[gpt] Results.
🌟 **AI investment news!** 🌟
1️ ⁇ ** AI investment by telecommunications companies** 📡
Telecoms are increasing their AI investment. However, it is said that the burden of frequency reallocation is high. For more information [Check here] (https://news.google.com/rss/articles/CBMiTkFVX3lxTE5xUEdrNHZZclQ4RUNmNGpqZG1COUNfckVOZ2hqQTJ4NGkwa0NRU0Q1azRQNzMwTTBJVDloQmNKamRZc3dic0plQWtEUTNXUQ)!
2️ ⁇ **CEO comments** 👔
Global CEOs have announced that they will "invest in AI unconditionally in the next three years." You say the staff will pick more! [Check here] (https://news.google.com/rss/articles/CBMiU0FVX3lxTFB1VDRjTlIxeHRjV3NKaERHMFJLOFNpUlNUVnZzQ0JvOUpISVE2cW9rbTZPVU9lQXZuUURJNHF0aDZyaDdQM0F5NFhsc0NrN1dHNEZz)!
3️ ⁇ **MIT Economist's Warning**
MIT economist warned companies that "there are only 5% jobs that will be affected by AI in the next 10 years." To learn more [Check here] (https://news.google.com/rss/articles/CBMiakFVX3lxTE9BQUtjd3pDS1dXRkZQTlo4Y2w2d2laZFFQRXdsbGlCMFRTcWJYLTNLaksxbFlnYzk3clVnYlFxZF93U2xubXY1VVhBTDQ2SDhLbm9hcDdXQ3prTlJtV0VCYTFINmNRbjR5N3c)!
4️ ⁇ ** Seattle medical AI investment** 🏥
Seattle is emerging as a mecca for medical AI as Amazon and MS invest in water tanks. [Check here] (https://news.google.com/rss/articles/CBMiWkFVX3lxTE5XeGtRRjRyeUFZZng4U2JWMmhZdFczSmR5d0YwbmF3cHpJVjRka2x4ZmRoVjdnaWdLOUdVSjNtN1FqeTBpTmRaUk9IZFFVamhGREZzQloxVmZ3UdIBVEFVX3lxTE9NVllVWHNUTTl1NWFXbHJPRHBEOVRiUTlCUmZtRHVZbXlMSl9MaFFsZUd0Yll0dUJNQk5UWjhfalNVV20tSjl3V01wcWtGSWl1Wk5KSg)!
5️ ⁇ **AI start-up investment attraction** 🚀
The AI company ‘Markvision’ attracted the investment of the 220 billion series A+. For more information [Check here] (https://news.google.com/rss/articles/CBMiSEFVX3lxTE9DQnVxNFNuYnBzdDFObDRpM292VHlpcTZNZUtEOUJNVE5KWTROR210NEtfZUszUnp6eWJELUg3SkdQeE80TnhsNA)!
👉 What are your thoughts? I look forward to seeing how AI investments will change in the future! 💡✨ #AI #Investment #News # Technology # Future
# claude
execute_agent(claude, tools, query, "claude")
[claude] Results.
[claude] Results.
Based on the search results, we will write in Instagram post format.
--- ---
📱 #AIInvestment #Textrend #Future technology
🔍 AI investment trends: global companies move
One. Telecom's AI investment expansion 🚀
-Increased burden of frequency reassignment
-Strategic moves to secure future competitiveness
2. Middle East Oil Machine Turns into Big Tech Fuel 💰
-Interested in AI corporate investment and construction of semiconductor factories
-Global technology industry version change notice
3. 2023 year creation AI investment boom continued 📈
-8 rounds of large-scale investment over 6700 billion won
-Expect AI technology development and market expansion
4. New Center for Medical AI, Seattle 🏥
-A large company invests in Amazon and Microsoft
-Fusion of healthcare and AI, paying attention to future medical innovation
5. Global CEOs Will to Invest in AI 💼
-64% CEO named AI a top investment
-Key strategies for strengthening corporate competitiveness and innovation
💡 AI technology is now a must, not a choice! How is your business prepared for the AI era? Share your thoughts with comments! 👇
#AIRevolution # Technician # Digital Transition #4 Differential Industry Revolution
--- ---
I've compiled news about AI investments in the form of Instagram posts like this. Hashtags, emoji, and concise yet interesting content configurations have been written to attract the attention of Instagram users. If necessary, please correct the content or tell us if you have any additional information.
[gemini] Results.
## 🔥 Hot AI investment news! Do not miss! 🔥
🤖 AI investments are hot these days, but you are wondering what is going on? 🤔
📰 Take a look at only the major news headlines!
* **AI carriers increasing investment, cost of frequency reassignment ** -Electronic
* **Global CEOs "In the next three years, AI investments,··, will also be picked up more employees"** -Nate News
* **MIT economist "Only 5% of jobs will be affected by AI for 10 years...Companies will only fly investment costs"**-AI Times
* **Amazon·MS invests in water tanker... Medical AI Mecca Seattle**- Korean Economy
* ** Artificial companies ‘Markvision’, 220 billion won series A+ Attract investment** -Flatum
#AI #Investment #Artificial #News # Don't miss it
# llama3.1 70B (Together.ai)
execute_agent(
llama,
tools,
"Search AI related news and write it in Instagram post format",
"llama3.1 70B",
)
[llama3.1 70B] Results.
Here's an Instagram post format for AI related news:
"Stay up-to-date with the latest AI news!
Meta's new AI-powered video generation tool, "MovieGen", has been released!
The SK AI Summit is happyning in Seoul, where expos and entrepreneurs will gather to discuss the future of AI and how to coexist with AGI.
A recent hurricane damage photo that went viral was actually created by AI!
Meta's AR technology is giving Apple a run for its money!
AI talent tech company, Glorand, has lauched its AI diagnosis SaaS'PSYT' in Japan.
Stay informed and join the conversation! #AI #ArtificialIntelligence #TechNews"
Sources:
-https://news.google.com/rss/articles/CBMiakFVX3lxTFB2MmRiRVZWWHlGNnhfTDFfRldrYllYSVBlNi1NRTBiN2xYMGc2NHhHY3JsUkF5dDR1aXdwRDBmZXI4QzUwNGQ0aU5NOG1ZUVQ1Y2MwQy1vS3dXTVQxbV9FanRqS1FDLW5RaGc?oc=5
-https://news.google.com/rss/articles/CBMiSEFVX3lxTE16M19mWXBHTnRPSlhCNkZzVmlSV0N1QjZKbXNlcHN5QWxVYVRUd3RaeTFSZkpleG40ZWRubWNTSzFaS0o1eGM4cQ?oc=5
-https://news.google.com/rss/articles/CBMiUkFVX3lxTE0yVFltQlZvRmVWajdYMnEzZ1RiSURGZVRXcGhXcEQxX2ZlZU1xRjFmUVR1b2wwN21jSEgwbTJKLWVaV05OeUlnMkNjZUF6N0oxTWc?oc=5
-https://news.google.com/rss/articles/CBMicEFVX3lxTFAxcFZmNkxjaXpqMy1fSjBlYUVSdTdmZGxWemdzVENuVEdBRGJOYWRtQmM5cUV4bUx4SWw3OF9OdUZYLW1Yb0hyQ3E2c05MVjRzaVpsQmRxVVFmTlJnZ2tjR00wOWVSNUVmcVFTUVlOVzU?oc=5
-https://news.google.com/rss/articles/CBMidkFVX3lxTE1qcVZOdzdEYkgxbUxzbWZlUUxRMjhTZFNJdUxab3VRWXdXQXZ5bUd1OG43WGE1QnRUbHJqNkxFSmtTRVpTamdYRDlNR3J4WjROcU1nRTdTTFFYX1FQOGFWMHAwUURxbHljYVZmTGFkVmRSNTFTc0HSAWZBVV95cUxPUFAxeHZabF9hWDlLZE9tS1V6SWFNSkJzYnl4SWJsa0h4d2NzMEdkUm1ROHNxU2xaa2h0VTZodHppU240R3V0MEtjaGJzRllTNF82bnJEQ1hCdHJUa25naEZUMEhzWHc?oc=5
[llama3.1 (Ollama)] Results.
**AI Investment News**
* BRIDGET, developed by Bridgewise, is the world's first interactive AI investment tool, providing regulatory-compliant investment recommendations.
* Midiweil secured 15.8 billion won in series B2 funding, exceeding 30.5 billion won in total investment.
* GAIIP has launched a global project for large-scale AI infrastructure investments.
* Platag has challenged the AI behavior analysis industry.
**Instagram postings**
"AI Investment News!
Bridgewise's BRIDGET, the world's first interactive AI investment tool!
Midiweil secures 15.8 billion won in series B2 funding!
GAIIP launches large-scale AI infrastructure investment project!
Playtags Challenges AI Behavior Analysis Industry!
#AInvestment #Bridgewise #BRIDGET #Mediwhale #GAIIP #Playtag"