Skip to content

Commit

Permalink
Remove docstrings from nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
rlancemartin committed Sep 17, 2024
1 parent a814f95 commit 7c574fb
Showing 1 changed file with 0 additions and 74 deletions.
74 changes: 0 additions & 74 deletions src/enrichment_agent/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ async def call_agent_model(
3. Initializes and configures the LLM with available tools.
4. Invokes the LLM and processes its response.
5. Handles the LLM's decision to either continue research or submit final info.
Args:
state (State): The current state of the research process, including topic and extraction schema.
config (Optional[RunnableConfig]): Configuration for the LLM, if provided.
Returns:
Dict[str, Any]: A dictionary containing:
- 'messages': List of response messages from the LLM.
- 'info': Extracted information if the LLM decided to submit final info, else None.
- 'loop_step': Incremented step count for the research loop.
Note:
- The function uses three tools: scrape_website, search, and a dynamic 'Info' tool.
- If the LLM calls the 'Info' tool, it's considered as submitting the final answer.
- If the LLM doesn't call any tool, a prompt to use a tool is appended to the messages.
"""
# Load configuration from the provided RunnableConfig
configuration = Configuration.from_runnable_config(config)
Expand Down Expand Up @@ -121,24 +106,6 @@ async def reflect(
4. Initializes and configures a language model with structured output.
5. Invokes the model to assess the quality of the gathered information.
6. Processes the model's response and determines if the info is satisfactory.
Args:
state (State): The current state of the research process, including topic,
extraction schema, and gathered information.
config (Optional[RunnableConfig]): Configuration for the language model, if provided.
Returns:
Dict[str, Any]: A dictionary containing either:
- 'info': The presumed info if it's deemed satisfactory.
- 'messages': A list with a ToolMessage indicating an error or unsatisfactory result.
Raises:
ValueError: If the last message in the state is not an AIMessage with tool calls.
Note:
- This function acts as a quality check for the information gathered by the agent.
- It uses a separate language model invocation to critique the gathered info.
- The function can either approve the gathered info or request further research.
"""
p = prompts.MAIN_PROMPT.format(
info=json.dumps(state.extraction_schema, indent=2), topic=state.topic
Expand Down Expand Up @@ -202,24 +169,6 @@ def route_after_agent(
1. Error recovery: If the last message is unexpectedly not an AIMessage.
2. Info submission: If the agent has called the "Info" tool to submit findings.
3. Continued research: If the agent has called any other tool.
Args:
state (State): The current state of the research process, including
the message history.
Returns:
Literal["reflect", "tools", "call_agent_model", "__end__"]:
- "reflect": If the agent has submitted info for review.
- "tools": If the agent has called a tool other than "Info".
- "call_agent_model": If an unexpected message type is encountered.
Note:
- The function assumes that normally, the last message should be an AIMessage.
- The "Info" tool call indicates that the agent believes it has gathered
sufficient information to answer the query.
- Any other tool call indicates that the agent needs to continue research.
- The error recovery path (returning "call_agent_model" for non-AIMessages)
serves as a safeguard against unexpected states.
"""
last_message = state.messages[-1]

Expand All @@ -242,29 +191,6 @@ def route_after_checker(
This function determines whether to continue the research process or end it
based on the checker's evaluation and the current state of the research.
Args:
state (State): The current state of the research process, including
the message history, info gathered, and loop step count.
config (RunnableConfig): Configuration object containing settings like
the maximum number of allowed loops.
Returns:
Literal["__end__", "call_agent_model"]:
- "__end__": If the research process should terminate.
- "call_agent_model": If further research is needed.
The function makes decisions based on the following criteria:
1. If the maximum number of loops has been reached, it ends the process.
2. If no info has been gathered yet, it continues the research.
3. If the last message indicates an error or unsatisfactory result, it continues the research.
4. If none of the above conditions are met, it assumes the result is satisfactory and ends the process.
Note:
- The function relies on a Configuration object derived from the RunnableConfig.
- It checks the loop_step against max_loops to prevent infinite loops.
- The presence of info and its quality (determined by the checker) influence the decision.
- An error status in the last message triggers additional research.
"""
configurable = Configuration.from_runnable_config(config)
last_message = state.messages
Expand Down

0 comments on commit 7c574fb

Please sign in to comment.