Repository: truera/trulens
Issue: [Bug] TruChain with AgentExecutor breaks LangChain
Root cause: Interface Contract Mismatch

This bug affects release 0.9.0 and it was probably introduced with #362 (I tested with the codebase before and after the merge, before it works fine).

### Context
While trying to reproduce [this example from LangChain](https://python.langchain.com/docs/modules/agents/agent_types/openai_functions_agent) I noticed that the `TruChain` with an `AgentExecutor` causes `TypeError: 'NoneType' object is not subscriptable` in `langchain.chains.base`

### Reproduce
```python
from langchain import LLMMathChain
from langchain.agents import initialize_agent, Tool, AgentType
from langchain.chat_models import ChatOpenAI
from trulens_eval import Tru, TruChain

llm=ChatOpenAI(temperature=0, model="gpt-3.5-turbo-0613")

llm_math_chain = LLMMathChain.from_llm(llm, verbose=True)

tools = [
    Tool(
        name="Calculator",
        func=llm_math_chain.run,
        description="useful for when you need to answer questions about math"
    ),
]

agent = initialize_agent(tools, llm, agent=AgentType.OPENAI_FUNCTIONS, verbose=True)

app = TruChain(agent)

# works fine
agent(inputs={"input": "how much is Euler's number divided by PI"})

# raises `TypeError: 'NoneType' object is not subscriptable`
app(inputs={"input": "how much is Euler's number divided by PI"})
```
Output logs and stacktrace here: [logs.txt](https://github.com/truera/trulens/files/12323098/logs.txt)

Thanks for report. Take a look at https://github.com/truera/trulens/pull/376 for fix.

Tested this with trulens-eval 0.10.0, it doesn't break anymore but it prints a couple warnings:
```
A new object of type <class 'langchain.chains.llm_math.base.LLMMathChain'> at 0x7ff89668ef00 is calling an instrumented method <function Chain.__call__ at 0x7ff8a74ab5e0>. The path of this call may be incorrect.
Guessing path of new object is *.app based on other object (0x7ff8965c0300) using this function.
A new object of type <class 'langchain.chains.llm.LLMChain'> at 0x7ff8974d86c0 is calling an instrumented method <function Chain.__call__ at 0x7ff8a74ab5e0>. The path of this call may be incorrect.
Guessing path of new object is *.app based on other object (0x7ff8965c0300) using this function.
```
Should that be Ok?

Hi, this is happening because our walk over the agent is not finding all of the relevant components that need instrumentation but at the same time it has walked over and instrumented other components that have the same class/methods that the undiscovered components use. Because of this, we cannot be sure where in the app structure these components are located when we see them invoking methods. If you do not care what their location is listed as in the dashboard or otherwise, this may be ok for you. If you do care about the paths, this is not ok. I am investigating the enumeration of agent components to address this.

Investigating further I see this may all be because the components are hidden behind a method (the `func` attribute of `Tool`) which we do not inspect when instrumenting components. Will think about how to address this but there is no current plan to fix the path of components that appear only inside closures like this.

I am adding more agent components to instrument that helps a little with this issue but is not perfect (https://github.com/truera/trulens/pull/406). Things like `Tool._run` now show up in the dashboard with their correct path (see first screenshot), but the LLM call involved in the tool run that is performed by `Tool.func` has the wrong path (see second screenshot).
![Screenshot 2023-08-29 at 11 56 27](https://github.com/truera/trulens/assets/421701/734eaf45-91e1-480a-9ed1-04476a10a663)
![Screenshot 2023-08-29 at 11 56 39](https://github.com/truera/trulens/assets/421701/bf928813-d812-40b2-834c-716ac6ae03a2)



logging message issue is fixed. Expanded topic is ok as is