From 5bf10af190745299cecebf8eab2cfe8502e6dbf5 Mon Sep 17 00:00:00 2001 From: Jeff Haynie Date: Sat, 4 Oct 2025 15:40:30 -0500 Subject: [PATCH] Remove the temperature override since its model based --- common/js/langchain.ts | 5 ++--- common/js/langgraph.ts | 3 +-- common/py/autogen.py | 39 ++++++++++++++++++-------------- common/py/langgraph.py | 50 +++++++++++++++++++++++++++--------------- 4 files changed, 58 insertions(+), 39 deletions(-) diff --git a/common/js/langchain.ts b/common/js/langchain.ts index 02e7aa6..e319399 100644 --- a/common/js/langchain.ts +++ b/common/js/langchain.ts @@ -33,15 +33,14 @@ export default async function LangChainAgent( // Create a ChatOpenAI model const model = new ChatOpenAI({ model: 'gpt-5-mini', - temperature: 0, }); // Create a prompt template const prompt = ChatPromptTemplate.fromTemplate(` You are an expert in LangChain, the TypeScript/JavaScript framework for building LLM-powered applications. - You specialize in explaining chains, agents, memory management, prompt templates, output parsers, and + You specialize in explaining chains, agents, memory management, prompt templates, output parsers, and building production-ready AI applications. Provide detailed, practical information about LangChain development. - + Human: {input} Assistant:`); diff --git a/common/js/langgraph.ts b/common/js/langgraph.ts index 0c84b64..579e449 100644 --- a/common/js/langgraph.ts +++ b/common/js/langgraph.ts @@ -33,7 +33,6 @@ export default async function LangGraphAgent( // Create a ChatOpenAI model const model = new ChatOpenAI({ model: 'gpt-5-mini', - temperature: 0, }); // Create a prompt template @@ -41,7 +40,7 @@ export default async function LangGraphAgent( You are an expert in LangGraph, the TypeScript framework for building stateful AI agents with graph-based workflows. You specialize in explaining StateGraph architecture, node and edge definitions, tool integration, human-in-the-loop controls, persistence, and ReAct patterns. Provide detailed, practical information about LangGraph development including code examples. - + Human: {input} Assistant:`); diff --git a/common/py/autogen.py b/common/py/autogen.py index 6a9ac0e..c80a219 100644 --- a/common/py/autogen.py +++ b/common/py/autogen.py @@ -5,50 +5,57 @@ from autogen_core import CancellationToken from autogen_ext.models.openai import OpenAIChatCompletionClient + def welcome(): return { "welcome": "Welcome to the Microsoft AutoGen Agent! I can help you build multi-agent conversational AI applications with collaborative workflows.", "prompts": [ { "data": "Show me how multiple agents can collaborate on a complex task", - "contentType": "text/plain" + "contentType": "text/plain", }, { "data": "What are the advantages of using AutoGen for multi-agent systems?", - "contentType": "text/plain" - } - ] + "contentType": "text/plain", + }, + ], } + async def run(request: AgentRequest, response: AgentResponse, context: AgentContext): try: - user_message = await request.data.text() or "Hello! Tell me about Microsoft AutoGen and how agents collaborate." - + user_message = ( + await request.data.text() + or "Hello! Tell me about Microsoft AutoGen and how agents collaborate." + ) + # Create model client - model_client = OpenAIChatCompletionClient(model="gpt-4o-mini", temperature=0.7) - + model_client = OpenAIChatCompletionClient(model="gpt-4o-mini") + # Create an AssistantAgent with OpenAI model assistant = AssistantAgent( name="assistant", model_client=model_client, - system_message="You are a helpful AI assistant specializing in multi-agent systems and collaborative AI workflows. Provide detailed, informative responses about how agents can work together to solve complex problems." + system_message="You are a helpful AI assistant specializing in multi-agent systems and collaborative AI workflows. Provide detailed, informative responses about how agents can work together to solve complex problems.", ) - + # Create a message from the user message = TextMessage(content=user_message, source="user") cancellation_token = CancellationToken() - + # Send message to assistant and get response agent_response = await assistant.on_messages([message], cancellation_token) - + # Close the model client connection await model_client.close() - + # Extract the response text response_text = agent_response.chat_message.content - + return response.text(response_text) - + except Exception as e: context.logger.error(f"Error running AutoGen agent: {e}") - return response.text("Sorry, there was an error processing your request with the AutoGen agents.") + return response.text( + "Sorry, there was an error processing your request with the AutoGen agents." + ) diff --git a/common/py/langgraph.py b/common/py/langgraph.py index df143e1..914fb1a 100644 --- a/common/py/langgraph.py +++ b/common/py/langgraph.py @@ -5,30 +5,32 @@ from langchain_core.messages import AIMessage from langchain_openai import ChatOpenAI + def welcome(): return { "welcome": "Welcome to the LangGraph Agent! I can help you build stateful AI agents with graph-based workflows and human-in-the-loop controls.", "prompts": [ { "data": "How do I create stateful agents with LangGraph workflows?", - "contentType": "text/plain" + "contentType": "text/plain", }, { "data": "What are the advantages of using graph-based agent architectures?", - "contentType": "text/plain" - } - ] + "contentType": "text/plain", + }, + ], } + # Define example tools for the LangGraph agent @tool def get_info(topic: str) -> str: """ Get information about a specific topic related to LangGraph and agent development. - + Args: topic (str): The topic to get information about - + Returns: str: Information about the topic """ @@ -36,29 +38,32 @@ def get_info(topic: str) -> str: "langgraph": "LangGraph is a framework for building stateful AI agents with graph-based workflows, human-in-the-loop controls, and persistence.", "stategraph": "StateGraph is the core component in LangGraph that defines the nodes and edges of your agent workflow.", "tools": "Tools in LangGraph are Python functions that agents can call to perform specific actions or retrieve information.", - "workflows": "Workflows in LangGraph are defined as graphs with nodes (functions) and edges (control flow) that enable complex agent behavior." + "workflows": "Workflows in LangGraph are defined as graphs with nodes (functions) and edges (control flow) that enable complex agent behavior.", } - + topic_lower = topic.lower() for key, value in info_database.items(): if key in topic_lower: return value - + return f"LangGraph is a powerful framework for building stateful AI agents. It provides graph-based workflows, tool integration, and human-in-the-loop controls for reliable agent development." + # List of available tools tools = [get_info] # Initialize the LLM and bind tools -model = ChatOpenAI(model="gpt-5-mini", temperature=0).bind_tools(tools) +model = ChatOpenAI(model="gpt-5-mini").bind_tools(tools) tool_node = ToolNode(tools) + def call_model(state: MessagesState) -> dict: """Node to call the agent model""" messages = state["messages"] response = model.invoke(messages) return {"messages": [response]} + def should_continue(state: MessagesState) -> str: """Determine whether to call tools or end the workflow""" last_message = state["messages"][-1] @@ -66,6 +71,7 @@ def should_continue(state: MessagesState) -> str: return "tools" return END + # Build the StateGraph workflow = StateGraph(MessagesState) workflow.add_node("agent", call_model) @@ -85,28 +91,36 @@ def should_continue(state: MessagesState) -> str: # Compile the graph agent_graph = workflow.compile() + async def run(request: AgentRequest, response: AgentResponse, context: AgentContext): try: - user_message = await request.data.text() or "Tell me about LangGraph and how it helps build stateful AI agents." - + user_message = ( + await request.data.text() + or "Tell me about LangGraph and how it helps build stateful AI agents." + ) + # Create initial state with user message initial_state = {"messages": [("human", user_message)]} - + # Run the LangGraph workflow final_state = None for chunk in agent_graph.stream(initial_state, stream_mode="values"): if "messages" in chunk and chunk["messages"]: final_state = chunk - + # Extract the final response if final_state and "messages" in final_state and final_state["messages"]: # Get the last AI message for message in reversed(final_state["messages"]): if isinstance(message, AIMessage): return response.text(message.content) - - return response.text("I'd be happy to help you learn about LangGraph and building stateful AI agents! Please ask me about graph-based workflows, tools, or agent architecture.") - + + return response.text( + "I'd be happy to help you learn about LangGraph and building stateful AI agents! Please ask me about graph-based workflows, tools, or agent architecture." + ) + except Exception as e: context.logger.error(f"Error running LangGraph agent: {e}") - return response.text("Sorry, there was an error processing your request with the LangGraph agent.") + return response.text( + "Sorry, there was an error processing your request with the LangGraph agent." + )