File size: 913 Bytes
0c0b2ef
 
4995bb4
0c0b2ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from app.state.state import EmailAgentState
from langchain_groq import ChatGroq
from app.utils.token_utils import count_input_tokens


def check_token_count_node(state: EmailAgentState):
    """
    This is a formal Node. It calculates tokens and can 
    update the state if you add a 'token_count' key to your TypedDict.
    """
    subject = state.get('sender_subject', "")
    body = state.get('sender_email_body', "") 
    
    tokens = count_input_tokens(subject, body)
    print(f"--- NODE: Token Count calculated as {tokens} ---")
    
    # We return the count so it's stored in the state for the next router to see
    return {"sender_email_token_count": tokens}


def check_token_limit_router(state: EmailAgentState):
    """
    Acts as a router to decide if we need summarization.
    """
    if state.get("sender_email_token_count", 0) > 100000:

        return "summarize"
    
    return "triage"