Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: pub@towardsai.net
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab VeloxTrend Ultrarix Capital Partners Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Our 15 AI experts built the most comprehensive, practical, 90+ lesson courses to master AI Engineering - we have pathways for any experience at Towards AI Academy. Cohorts still open - use COHORT10 for 10% off.

Publication

LangGraph Beginner to Advance: Part 3: Multi-Entries Inputs for State in LangGraph
Artificial Intelligence   Latest   Machine Learning

LangGraph Beginner to Advance: Part 3: Multi-Entries Inputs for State in LangGraph

Last Updated on September 29, 2025 by Editorial Team

Author(s): Talib

Originally published on Towards AI.

So now we’re about to build our second graph as you can see here. And it’s again quite similar to the first graph we built except now we’re going to be able to pass multiple inputs as you can see here. So again, what are the objectives which you will be learning in this? Well, we’re going to build a more complicated agent state. And we’re going to be creating a processing node that performs operations on list data. So now we’re about to see how we can really work with different data types apart from just string. And we’re going to set up the entire graph that processes and outputs these and computes these results. And we’re going to be able to invoke the graph with the structured inputs and retrieve the outputs. But the main goal which I want you to be able to learn in this specific subsection is really how to handle multiple inputs. All right. Okay. Let’s code this.

LangGraph Beginner to Advance: Part 3: Multi-Entries Inputs for State in LangGraph

Step 1: Imports

Okay. So now let’s actually code the second graph up the second application up. I’ve just imported the same things again the type dictionary and the state graph. And I’ve also imported the list this time. But list is just a simple data structure which you should know already.

from typing import List
from langgraph.graph import StateGraph
from typing_extensions import TypedDict

Step 2: Implement the State Schema

If you remember from the previous graph we made we are supposed to implement the state schema first right. And, how do we do that? Again we use the class agent state type dictionary.

class AgentState(TypedDict):
values: List[int]
name: str
result: str

Before I continue just a heads up I could have named the state schema anything I want. I could have named it something arbitrary completely like a bottle for example. In this case I’ve just said agent state because one that’s how I learned it. It’s like a habit for me now. But it also really tells you what it actually is. It’s the state of your agent, right? So that’s why I’ve just kept it like that. But again, just a heads up, you could have named this whatever you want.

If you remember the main goal for this graph for this building this graph was to be able to handle and process multiple different inputs, right? So how do we actually assign and really do that? Well, the answer is in the state. This is just a type dictionary. You basically have multiple keys now you create that. Let’s say something like values list integers. Let’s say one of our input is a list of integers and let’s also pass in a name which will obviously be in a string and let’s have the result in a string something completely random. But now you can see we’re now operating on two different types of data structures. A list of integers and a string. And we’re handling three different inputs values name result.

Step 3: Build the Processing Node

Now let’s actually build our node because in again in this graph we’re just going to have a single node to keep things easy. Remember step by step.

def process_values(state: AgentState) -> AgentState:
"""
Function process handles multiple different inputs.
"
""
state["result"] = f"Hi there {state['name']}, your sum is equal to {sum(state['values'])}"
return state

Never forget to add an explainintion after difining the function. Building healthy habits is important. I know it’s annoying. We have to write the doc string. But I am just doing this to build healthy habits.

Step 4: Create the Graph

Now we actually create the graph. Again, this is going to be very very similar to what we did in the previous section because again there’s just a node, there’s a start point and an endpoint.

graph = StateGraph(AgentState)
graph.add_node("processor", process_values)graph.set_entry_point("processor")
graph.set_finish_point("processor")
app = graph.compile()

We use the state graph to initialize a graph and we pass in our state schema. We add our node and give it the name processor. This could be anything you want. Entry point and finish point are both the same because we only have one node. Then we compile the graph.

Step 5: Invoke the Graph

So now let’s actually test this. Let’s actually invoke this graph. Make sure to store your compiled graph in a variable because if you invoke the graph i.e. if you write something like graph.invoke that will not make sense because you haven’t compiled the graph. That’s why you need to invoke using app.

answers = app.invoke({
"values": [1, 2, 3, 4],
"name": "Steve"
})
print(answers)

Output:

{'values': [1, 2, 3, 4], 'name': 'Steve', 'result': 'Hi there Steve, your sum is equal to 10'}

If you want just the result:

print(answers["result"])

Output:

Hi there Steve, your sum is equal to 10

Optional Step: Print State Before and After

Now I want to try one more thing just to build your understanding a bit more. Let’s put some print statements here. So let’s have a print state before the action and then we print the state after.

def process_values(state: AgentState) -> AgentState:
print("Before:", state)
state["result"] = f"Hi there {state['name']}, your sum is equal to {sum(state['values'])}"
print("After:", state)
return state

Example output:

Before: {'values': [1, 2, 3, 4], 'name': 'Steve', 'result': None}
After: {'values': [1, 2, 3, 4], 'name': 'Steve', 'result': 'Hi there Steve, your sum is equal to 10'}

Notice I didn’t pass results as an input as well. I could have done that but Langraph automatically sets that as like a none value in this case if you don’t pass an input.

Now here’s where you need to be cautious. If I had actually used state result here as well to update state result like I used state result to update either itself or something else then you would run into a problem because your state result has been initialized as none because you didn’t pass it as an input. So be mindful of that.

Exercise

Welcome to the exercise, your second ever exercise. For this exercise, I want you to create a graph which passes in a single list of integers along with a name and an operation this time. And if the operation is a plus, you add the elements. And if it is times, you multiply all the elements all within the same node. So don’t create an extra node yet.

For example your input could be:

name = "jack sparrow"
values = [1, 2, 3, 4]
operation = "multiplication"

Your output should be:

Hi jack sparrow your answer is 24

Hint: you would need an if statement in your node so slightly more complicated but the whole concept is the same.

Hopefully you understood that. Again it should have been quite intuitive and interpretable. To solidify your understanding even more complete the exercise. Once you’ve completed this exercise we will move on to the third graph.

Catch the whole LangGraph Series here: LangGraph Reading List

Code is available here: LangGraph Github

Thank you for reading!

Let’s connect on LinkedIn!

Subscribe to my FREE AI NEWSLETTER | Mohammed Talib | Substack

I like to break down complex topics in simple words

substack.com

You might be interested in Reading!

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI


Take our 90+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

Towards AI has published Building LLMs for Production—our 470+ page guide to mastering LLMs with practical projects and expert insights!


Discover Your Dream AI Career at Towards AI Jobs

Towards AI has built a jobs board tailored specifically to Machine Learning and Data Science Jobs and Skills. Our software searches for live AI jobs each hour, labels and categorises them and makes them easily searchable. Explore over 40,000 live jobs today with Towards AI Jobs!

Note: Content contains the views of the contributing authors and not Towards AI.