from tensorlake.applications import application, function, Image
# Each framework gets its own container image with its own dependencies
langgraph_image = Image().run("pip install langgraph langchain-openai tavily-python")
openai_image = Image().run("pip install openai-agents")
claude_image = Image().run("pip install claude-agent-sdk")
deep_image = Image().run("pip install deepagents langchain-openai")
@function(image=langgraph_image, timeout=600)
def market_researcher(company: str) -> str:
"""Market research using a LangGraph ReAct agent with web search."""
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
from langchain_community.tools import TavilySearchResults
agent = create_react_agent(
ChatOpenAI(model="gpt-4o"),
tools=[TavilySearchResults(max_results=5)],
)
result = agent.invoke({"messages": [
("human", f"Research the market position, competitors, and recent news for {company}.")
]})
return result["messages"][-1].content
@function(image=openai_image, timeout=600)
def financial_analyst(company: str) -> str:
"""Financial analysis using an OpenAI Agents SDK agent with tool use."""
from agents import Agent, Runner, WebSearchTool
agent = Agent(
name="FinancialAnalyst",
instructions=(
"You are a financial analyst. Analyze revenue, margins, cash flow, "
"and valuation metrics. Use web search to find the latest filings."
),
tools=[WebSearchTool()],
)
result = Runner.run_sync(agent, f"Analyze the financials for {company}")
return result.final_output
@function(image=claude_image, timeout=900, ephemeral_disk=4)
def risk_assessor(company: str) -> str:
"""Risk assessment using a Claude agent with deep reasoning."""
import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions
async def run():
result = ""
async for message in query(
prompt=f"Assess regulatory, operational, and market risks for {company}.",
options=ClaudeAgentOptions(
system_prompt="You are a risk analyst. Identify and score key risks.",
permission_mode="acceptEdits",
cwd="/tmp/workspace",
),
):
result = str(message)
return result
return asyncio.run(run())
@function(image=deep_image, timeout=900)
def technical_reviewer(company: str) -> str:
"""Technical deep-dive using a Deep Agent with planning and web search."""
from deepagents import create_deep_agent
agent = create_deep_agent(
model="openai:gpt-4o",
system_prompt="Evaluate the company's technology stack, patents, and engineering culture.",
)
result = agent.invoke({
"messages": [{"role": "user", "content": f"Technical review of {company}"}]
})
return result["messages"][-1].content
@function(timeout=300)
def compile_analysis(market: str, financials: str, risks: str, technical: str, company: str) -> dict:
"""Combine all analyst reports into a final recommendation."""
return {
"company": company,
"market_research": market,
"financial_analysis": financials,
"risk_assessment": risks,
"technical_review": technical,
}
@application()
@function()
def analyze_company(company: str) -> dict:
# Four frameworks, four containers, all running in parallel
market = market_researcher.awaitable(company)
financials = financial_analyst.awaitable(company)
risks = risk_assessor.awaitable(company)
technical = technical_reviewer.awaitable(company)
return compile_analysis.awaitable(market, financials, risks, technical, company)