Please create two "number" datatype fields in the Lead and Contacts each named as "Total Incoming SMS" & "Total Outgoing SMS"
Then create two Process Builders - one for Incoming SMS Object(to calculate Total Incoming SMS) and the other for SMS History Object(to calculate Total Outgoing SMS)
The Criteria would be to check if the Incoming SMS/Outgoing SMS is associated to the Lead or/and Contact.
Then use a Field Update and increase the count, of the Total Incoming SMS if you receive an incoming response or the Total Outgoing SMS if you send a text message from Salesforce, by one.
Let me know if you have any further questions.